aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorinder123 <inder123@gmail.com>2015-08-08 09:10:48 -0700
committerinder123 <inder123@gmail.com>2015-08-08 09:10:48 -0700
commit0a93efada5edd251516eb6927b295a1bd1864509 (patch)
tree6ee08d7b67306aa00db7363869158c94f7786123
parentf73f8e063bd37427fd6c1b6986f41f274c17b22e (diff)
parent6e57df7e9648f4a48b500ac9a181a058829bcee1 (diff)
downloadandroid_external_gson-0a93efada5edd251516eb6927b295a1bd1864509.tar.gz
android_external_gson-0a93efada5edd251516eb6927b295a1bd1864509.tar.bz2
android_external_gson-0a93efada5edd251516eb6927b295a1bd1864509.zip
Merge pull request #652 from schlan/fix_turkish_locale_issues
Fix issues if runing in an environment with a Turkish locale
-rw-r--r--gson/src/main/java/com/google/gson/FieldNamingPolicy.java5
-rw-r--r--gson/src/test/java/com/google/gson/functional/FieldNamingTest.java29
2 files changed, 22 insertions, 12 deletions
diff --git a/gson/src/main/java/com/google/gson/FieldNamingPolicy.java b/gson/src/main/java/com/google/gson/FieldNamingPolicy.java
index 21863f9c..6b4c72ca 100644
--- a/gson/src/main/java/com/google/gson/FieldNamingPolicy.java
+++ b/gson/src/main/java/com/google/gson/FieldNamingPolicy.java
@@ -17,6 +17,7 @@
package com.google.gson;
import java.lang.reflect.Field;
+import java.util.Locale;
/**
* An enumeration that defines a few standard naming conventions for JSON field names.
@@ -88,7 +89,7 @@ public enum FieldNamingPolicy implements FieldNamingStrategy {
*/
LOWER_CASE_WITH_UNDERSCORES() {
public String translateName(Field f) {
- return separateCamelCase(f.getName(), "_").toLowerCase();
+ return separateCamelCase(f.getName(), "_").toLowerCase(Locale.ENGLISH);
}
},
@@ -111,7 +112,7 @@ public enum FieldNamingPolicy implements FieldNamingStrategy {
*/
LOWER_CASE_WITH_DASHES() {
public String translateName(Field f) {
- return separateCamelCase(f.getName(), "-").toLowerCase();
+ return separateCamelCase(f.getName(), "-").toLowerCase(Locale.ENGLISH);
}
};
diff --git a/gson/src/test/java/com/google/gson/functional/FieldNamingTest.java b/gson/src/test/java/com/google/gson/functional/FieldNamingTest.java
index 54db150c..5d326af8 100644
--- a/gson/src/test/java/com/google/gson/functional/FieldNamingTest.java
+++ b/gson/src/test/java/com/google/gson/functional/FieldNamingTest.java
@@ -21,6 +21,8 @@ import static com.google.gson.FieldNamingPolicy.LOWER_CASE_WITH_DASHES;
import static com.google.gson.FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES;
import static com.google.gson.FieldNamingPolicy.UPPER_CAMEL_CASE;
import static com.google.gson.FieldNamingPolicy.UPPER_CAMEL_CASE_WITH_SPACES;
+
+import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.SerializedName;
@@ -28,45 +30,51 @@ import junit.framework.TestCase;
public final class FieldNamingTest extends TestCase {
public void testIdentity() {
- Gson gson = new GsonBuilder().setFieldNamingPolicy(IDENTITY).create();
+ Gson gson = getGsonWithNamingPolicy(IDENTITY);
assertEquals("{'lowerCamel':1,'UpperCamel':2,'_lowerCamelLeadingUnderscore':3," +
"'_UpperCamelLeadingUnderscore':4,'lower_words':5,'UPPER_WORDS':6," +
- "'annotatedName':7}",
+ "'annotatedName':7,'lowerId':8}",
gson.toJson(new TestNames()).replace('\"', '\''));
}
public void testUpperCamelCase() {
- Gson gson = new GsonBuilder().setFieldNamingPolicy(UPPER_CAMEL_CASE).create();
+ Gson gson = getGsonWithNamingPolicy(UPPER_CAMEL_CASE);
assertEquals("{'LowerCamel':1,'UpperCamel':2,'_LowerCamelLeadingUnderscore':3," +
"'_UpperCamelLeadingUnderscore':4,'Lower_words':5,'UPPER_WORDS':6," +
- "'annotatedName':7}",
+ "'annotatedName':7,'LowerId':8}",
gson.toJson(new TestNames()).replace('\"', '\''));
}
public void testUpperCamelCaseWithSpaces() {
- Gson gson = new GsonBuilder().setFieldNamingPolicy(UPPER_CAMEL_CASE_WITH_SPACES).create();
+ Gson gson = getGsonWithNamingPolicy(UPPER_CAMEL_CASE_WITH_SPACES);
assertEquals("{'Lower Camel':1,'Upper Camel':2,'_Lower Camel Leading Underscore':3," +
"'_ Upper Camel Leading Underscore':4,'Lower_words':5,'U P P E R_ W O R D S':6," +
- "'annotatedName':7}",
+ "'annotatedName':7,'Lower Id':8}",
gson.toJson(new TestNames()).replace('\"', '\''));
}
public void testLowerCaseWithUnderscores() {
- Gson gson = new GsonBuilder().setFieldNamingPolicy(LOWER_CASE_WITH_UNDERSCORES).create();
+ Gson gson = getGsonWithNamingPolicy(LOWER_CASE_WITH_UNDERSCORES);
assertEquals("{'lower_camel':1,'upper_camel':2,'_lower_camel_leading_underscore':3," +
"'__upper_camel_leading_underscore':4,'lower_words':5,'u_p_p_e_r__w_o_r_d_s':6," +
- "'annotatedName':7}",
+ "'annotatedName':7,'lower_id':8}",
gson.toJson(new TestNames()).replace('\"', '\''));
}
public void testLowerCaseWithDashes() {
- Gson gson = new GsonBuilder().setFieldNamingPolicy(LOWER_CASE_WITH_DASHES).create();
+ Gson gson = getGsonWithNamingPolicy(LOWER_CASE_WITH_DASHES);
assertEquals("{'lower-camel':1,'upper-camel':2,'_lower-camel-leading-underscore':3," +
"'_-upper-camel-leading-underscore':4,'lower_words':5,'u-p-p-e-r_-w-o-r-d-s':6," +
- "'annotatedName':7}",
+ "'annotatedName':7,'lower-id':8}",
gson.toJson(new TestNames()).replace('\"', '\''));
}
+ private Gson getGsonWithNamingPolicy(FieldNamingPolicy fieldNamingPolicy){
+ return new GsonBuilder()
+ .setFieldNamingPolicy(fieldNamingPolicy)
+ .create();
+ }
+
@SuppressWarnings("unused") // fields are used reflectively
private static class TestNames {
int lowerCamel = 1;
@@ -76,5 +84,6 @@ public final class FieldNamingTest extends TestCase {
int lower_words = 5;
int UPPER_WORDS = 6;
@SerializedName("annotatedName") int annotated = 7;
+ int lowerId = 8;
}
}