But Event class i have is auto generated and I cannot add annotation on the getter method. Is there any other solution to make this work?
On Tuesday, August 4, 2020 at 2:37:32 PM UTC-4, Tatu Saloranta wrote: > > On Tue, Aug 4, 2020 at 11:24 AM ajay mundru <[email protected] > <javascript:>> wrote: > > > > In Event class POJO > > > > @JsonProperty("aDocId") > > private String aDocId = null; > > > > public String getADocId() { > > return aDocId; > > } > > > > public void setADocId(String aDocId) { > > this.aDocId = aDocId; > > } > > > > > ------------------------------------------------------------------------------------- > > > > While doing a post request, > > > > Event event = (Event) object; > > HttpHeaders headers = new HttpHeaders(); > > headers.setContentType(MediaType.APPLICATION_JSON); > > HttpEntity<Event> entity = new HttpEntity<>(event, headers); > > String response = restTemplate.postForObject(url, entity, String.class); > > > -------------------------------------------------------------------------------------- > > > > response says message cannot be accepted as it has unidentified field > > > > As the json getting posted has duplicate fields with different case: > aDocId, adocId where as I expected only aDocId as per my Event class. > > > > I could not change anything in the POJO as it is a auto generated class > based on swagger. > > > > I am using Spring boot. Seeking for help to resolve this scenario. > > The problem here is that capitalization of `aDocId` is problematic and > does not really match implicit name that getter/setter would produce. > Because of this, Jackson things there are 2 different properties (with > different casing). > This only affects the specific case of single-lower-case-letter. > > There are 2 ways to resolve this: > > 1. Move `@JsonProperty` annotation to getter or setter -- there is no > need to annotate Field, usually, and since it is private, it should be > ignore if not annotated > 2. Add duplicate of `@JsonProperty` on getter or setter -- this will > link Field and getter/setter Methods to make them be part of one > single logical propery > > I hope this helps, > > -+ Tatu +- > -- You received this message because you are subscribed to the Google Groups "jackson-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/bfcbb3f3-4956-4f8d-88c8-5fb2032feaf9o%40googlegroups.com.
