Parse JSON with PascalCase property names #157
-
Hi, I am trying to parse a JSON representation of a camt.053 into an MxCamt05300112 Java object via MxCamt05300112.fromJson(). The Provide library expects lowerCamelCase for property names in JSON, so it will fail to parse if JSON uses PascalCase. Is there perhaps a way to configure the library to accept PascalCase property names? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, The fromJson is basically and abstraction of Gson where the JSON structure matches the jaxb generated model. Thus you can create your own Gson instance and use it, instead of the library fromJson
Notice I've added the offset date time adapter in the example above, since this is the current version of the library. We have just made the main branch compatible with Java 11, Jakarta and java.time. The Java 8 code was moved to a java8-maintenance branch. |
Beta Was this translation helpful? Give feedback.
Hi,
The fromJson is basically and abstraction of Gson where the JSON structure matches the jaxb generated model. Thus you can create your own Gson instance and use it, instead of the library fromJson
final Gson gson = getGsonBuilderWithCustomAdapters() .registerTypeAdapter(OffsetDateTime.class, new OffsetDateTimeJsonAdapter()) .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE) .setPrettyPrinting() .create();
Notice I've added the offset date time adapter in the example above, since this is the current version of the library. We have just made the main branch compatible with Java 11, Jakarta and java.time.
The Java 8 code was moved to a java8-maintenance branch.