Spring MVC 3.2.5 Unrecognized field Jackson
jackson, java, json, spring, spring-mvc
Solution
Since you have configured Spring MVC to work with `MappingJackson2HttpMessageConverter` you need to use the Jackson 2.x annotations (`com.fasterxml.*`) not the Jackson 1.x ones.
You can see that Spring MVC is correctly using Jackson 2.x from the exception you are getting
(nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException)
If you want to stick with Jackson 1.x (which you probably shouldn't do), you need to configure Spring MVC to work with `MappingJacksonHttpMessageConverter` instead
Problem
I upgraded my spring mvc to spring 3.2.5. Some of my rest calls are returning an Unrecognized field exception even when they are existing. Here's the error. ``` Resolving exception from handler [public com.app.common.web.datatables.DataTablesAjaxResponse<com.app.cms.consultation.dto.ActiveMedicationView> com.app.cms.consultation.controller.impl.ActiveMedicationControllerImpl.ajaxSearchActiveMedication(java.lang.String,com.app.common.web.datatables.DataTablesAjaxRequest)]: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Unrecognized field "sEcho" (class com.app.common.web.datatables.DataTablesAjaxRequest), not marked as ignorable (16 known properties: "displayStart", "sortedColumns", "searchQuery", "echo", "sortableColumns", "displayLength", "columnSearches", "dataProp", "hasRegex", "sortDirections", "searchColumns", "regexColumns" [truncated]]) at [Source: org.eclipse.jetty.server.HttpInput@4dc300ae; line: 1, column: 11] (through reference chain: com.app.common.web.datatables.DataTablesAjaxRequest["sEcho"]); nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "sEcho" (class com.app.common.web.datatables.DataTablesAjaxRequest), not marked as ignorable (16 known properties: "displayStart", "sortedColumns", "searchQuery", "echo", "sortableColumns", "displayLength", "columnSearches", "dataProp", "hasRegex", "sortDirections", "searchColumns", "regexColumns" [truncated]]) at [Source: org.eclipse.jetty.server.HttpInput@4dc300ae; line: 1, column: 11] (through reference chain: com.app.common.web.datatables.DataTablesAjaxRequest["sEcho"]) ``` Here's the class: ``` import java.io.Serializable; import java.util.List; import java.util.Map; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.codehaus.jackson.annotate.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class DataTablesAjaxRequest implements Serializable { private static final long serialVersionUID = 1L; @JsonProperty("sEcho") private String echo; @JsonProperty("iColumns") private int numColumns; @JsonProperty("sColumns") private String columns; @JsonProperty("iDisplayStart") private long displayStart; @JsonProperty("iDisplayLength") private int displayLength; @JsonProperty("amDataProp") private List<String> dataProp; @JsonProperty("sSearch") private String searchQuery; @JsonProperty("asSearch") private List<String> columnSearches; @JsonProperty("bRegex") private boolean hasRegex; @JsonProperty("abRegex") private List<Boolean> regexColumns; @JsonProperty("abSearchable") private List<Boolean> searchColumns; @JsonProperty("iSortingCols") private int sortingCols; @JsonProperty("aiSortCol") private List<Integer> sortedColumns; @JsonProperty("asSortDir") private List<String> sortDirections; @JsonProperty("abSortable") private List<Boolean> sortableColumns; @JsonProperty("aoFilters") private Map<String, String> filters; //Setters and getters ``` Here's the controller. That's calling the API ``` @RequestMapping(value = AJAX_SEARCH_MED, method = RequestMethod.POST) @ResponseBody DataTablesAjaxResponse<ActiveMedicationView> ajaxSearchActiveMedication( @PathVariable(PATH_PIN) String pin, @RequestBody DataTablesAjaxRequest request); ``` I am using Spring MVC 3.2.5 and org.codehaus.jackson - jackson-mapper-asl version 1.9.9 The message converter being used is `MappingJackson2HttpMessageConterter`. Everything is working when it was on version 3.1 however when I ugpraded to Spring 3.2.5 these errors are shown. UPDATE Here's the Request Headers ``` Host: localhost:8081 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0 Accept: application/json, text/javascript, */*; q=0.01 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Content-Type: application/json;charset=UTF-8 X-Requested-With: XMLHttpRequest Referer: http://localhost:8081/cms/patient/2012010000000019/doctor-notes.html Content-Length: 304 Cookie: JSESSIONID=1gyv2us4wq5fid9v26i59lz1p; __zlcid= Connection: keep-alive Pragma: no-cache Cache-Control: no-cache ``` Here's the Request Body ``` { "sEcho":1, "iColumns":7, "sColumns":"", "iDisplayStart":0, "iDisplayLength":10, "amDataProp":[ "prescriptionDtlId", "generic", "brand", "preparation", "startDate", "endDate", "sig" ], "aiSortCol":[ 0 ], "asSortDir":[ "asc" ], "iSortingCols":1, "abSortable":[ false, true, true, false, true, true, false ], "aoFilters":{ "generic":"" } } ```