我正在遵循一個簡單的Spring MVC REST示例。在PUT請求,我得到以下異常:Spring MVC REST Json轉換異常
org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Unrecognized field "property" (Class domain.Property), not marked as ignorable
at [Source: [email protected]; 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: [email protected]; line: 1, column: 14] (through reference chain: domain.Property["property"])
我收到以下JSON
{"property":
{
"name":"name",
"age":"22"
}
}
以下是我的休息方法:
@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;
}
的Property
是標準的POJO吸氣劑/二傳手姓名和年齡。
如何解決此異常?
請發佈您的「財產」類代碼。 –
你的JSON包含一個「屬性」值,屬性只包含''name「和」age「'你應該從你的JSON中刪除屬性。它應該只包含'{「name」:「name」,「age」:「22」}' –