How to solve org.codehaus.jackson.map.JsonMappingException: Unrecognized field
Jackson library is used with most REST/JSON applications in order to dynamically convert JSON to POJO and POJO to JSON. This tutorial explains how to solve the common exception raised by Jackson while doing the JSON/POJO conversion: org.codehaus.jackson.map.JsonMappingException: Unrecognized field
This exception occurs when Jackson tries to map a JSON attribute to a POJO field and couldn’t find a setter method for this attribute or a copy constructor.
Here below we explain the solutions to this issue.
1- Copy constructor/ Setter method
The first thing to check when facing such an issue is to make sure that the unrecognized field is set through either a copy constructor or a setter method.
If the field neither exists in a copy constructor nor it has a setter method, then Jackson won’t be able to map it hence throws an exception.
2- Double check the name of POJO field
If you’re sure that you set the field correctly in the POJO, then double check the name of the field. It should exactly match the name of the JSON attribute.
If you set the field through a setter method, then the name of your setter method should be like set<fieldName>(). (Knowing that the field name is CamelCase).
If you set the field through a copy constructor, then the name of the parameter should match the name of the JSON attribute.