Response from a client (rest call) has a json element like USERId. The related java variable is as below
@JsonProperty("USERId")
private String uSERId;
I am using spring RestTemplate to make this rest call and for mapping from JSON to JAVA I am using GSON. I have completely excluded jackson databind which is spring rest template's default mapper like below.
this.getMessageConverters().removeIf(converter -> converter.getClass().getName().equals(MappingJackson2HttpMessageConverter.class.getName()));
GsonHttpMessageConverter messageConverter = new GsonHttpMessageConverter();
messageConverter.setGson(gson);
this.getMessageConverters().add(messageConverter);
This way, I made sure only GSON is used for mapping.
When I directly hit client rest service on postman, I see this filed has a value - "USERId": "025076373". However the response object from RestTemplate doesnt have this field i.e., all other fields with proper java canonical naming are mapped properly. I mean all other fields in the respone object are mapped with values from response json. Response object doesnt have uSERId or the corresponding value.
I believe this issue is probably because of the weird naming convention, however the same works fine with MappingJackson2HttpMessageConverter.
I have tried debugging by writing an adapter and assigning it to gsonBuilder and then setting that to GsonHttpMessageConverter.
gsonBuilder.registerTypeHierarchyAdapter(String.class, new StringTypeAdapter().nullSafe())
While debugging the adapter, I could see all other fields except USERId.
Object mapper of jackson databind has a property MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, which I believe is the reason why the same field is working jackson. I couldnt find a similar property with GSON. Any pointers on how to fix this issue would be very helpful.
Technologies used : spring boot spring rest template com.google.code.gson:gson:2.8.6