Issue
When sending JSON requests to the server, I'm often greeted by this message:
The request sent by the client was syntactically incorrect ().
Usually it's an incorrect attribute that was passed that the controller didn't expect, since the object the JSON maps to doesn't contain it.
Finding the parameter is needlessly time consuming - is there a way to get more information, perhaps even a stack trace of the exception? I've tried running in debug mode and I'm using Jackson as my JSON (de)serialiser.
Solution
If the data that your consuming is from an external api and if you want to shield your controller from unnecessary elements/properties that you dont need you can use below annotation on POJO class
@JsonIgnoreProperties(ignoreUnknown = true)
or you could set it globally
//jackson 2.0
jsonObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Answered By - Sudhakar
Answer Checked By - Mary Flores (JavaFixing Volunteer)