In prototyping communication between .NET desktop app and Java server, using REST with JSON posts, I am running into a case-sensitivity issue. The .NET objects have there properties in Pascal Casing (which is conventional for .NET), eg: Symbol, EntryValue
(etc), while the Java representation of same object uses camel casing, eg symbol, entryValue
.
The server receives json value as:
{"EntrySize":100,"Symbol":"AMZN"}
But Gson doesn't deserialize in case-insensitive manner. Is there any way to get Gson to do this?
Use FieldNamingPolicy
on a GsonBuilder
, to get your Gson
object. Yours seems to match UPPER_CAMEL_CASE
.
Gson gson = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
.create();
For any exceptions, annotate your class field with a @SerializedName
annotation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.