Open GoogleCodeExporter opened 9 years ago
The solution for this is easy. On the latest svn pull, change line 91 of
FIeldNamingPolicy from: return separateCamelCase(f.getName(),
"_").toLowerCase(); to return separateCamelCase(f.getName(),
"_").toLowerCase(Locale.ROOT);
There are of course other toLowerCase/toUpperCase calls in that class that
would need to be changed as well. Unless the Locale.toLowerCase() using
default locale is a quirk specific to Android, this is a definite bug that
needs to be fixed. Is there somewhere I can submit a patch?
Original comment by alex.put...@starmakerinteractive.com
on 11 Feb 2014 at 9:45
Oh wow Oct 2013. Still, this bug persists in gson 2.2.4.
Original comment by alex.put...@starmakerinteractive.com
on 11 Feb 2014 at 9:46
If anyone else is having this issue, you can implement your own
FieldNamingStrategy to work around it.
public class LocaleAgnosticFieldNamingStrategy implements FieldNamingStrategy {
@Override
public String translateName(Field field) {
return separateCamelCase(field.getName(), "_").toLowerCase(Locale.ROOT);
}
/**
* Converts the field name that uses camel-case define word separation into
* separate words that are separated by the provided {@code separatorString}.
*/
private static String separateCamelCase(String name, String separator) {
StringBuilder translation = new StringBuilder();
for (int i = 0; i < name.length(); i++) {
char character = name.charAt(i);
if (Character.isUpperCase(character) && translation.length() != 0) {
translation.append(separator);
}
translation.append(character);
}
return translation.toString();
}
}
Original comment by alex.put...@starmakerinteractive.com
on 11 Feb 2014 at 9:48
Actually, here's a diff for the fix.
Original comment by alex.put...@starmakerinteractive.com
on 12 Feb 2014 at 2:14
Attachments:
Original issue reported on code.google.com by
j...@thumbsuplabs.com
on 30 Oct 2013 at 11:11