I am following a simple Spring MVC REST example. On PUT request, I am getting following exception:
org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Unrecognized field "property" (Class domain.Property), not marked as ignorable
at [Source: org.apache.catalina.connector.CoyoteInputStream@75280b93; line: 1, column: 14] (through reference chain: domain.Property["property"]);
nested exception is org.codehaus.jackson.map.exc.UnrecognizedPropertyException:
Unrecognized field "property" (Class domain.Property), not marked as ignorable
at [Source: org.apache.catalina.connector.CoyoteInputStream@75280b93; line: 1, column: 14] (through reference chain: domain.Property["property"])
I am receiving following JSON
{"property":
{
"name":"name",
"age":"22"
}
}
Following is my REST method:
@RequestMapping(method = RequestMethod.PUT, value = "/{id}")
public ResponseEntity<Property> updateProperty(@RequestBody Property property,
@PathVariable String id) {
final ResponseEntity<Property> response =
new ResponseEntity<Property>(property, HttpStatus.OK);
return response;
}
The Property is standard POJO with getter/setter for name and age.
How can I resolve this exception?
"name" and "age"You should remove the property from your JSON. It should only contain{ "name":"name", "age":"22" }