다음은 간단한 Spring MVC REST 예제이다. PUT 요청에, 나는 다음과 같은 예외 점점 오전 : 게터와Spring MVC REST Json 변환 예외
@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/:
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"
}
}
에 따라 수신하고 나의 REST 방식입니다 이름과 나이를 세터.
어떻게이 예외를 해결할 수 있습니까?
"Property"클래스 코드도 올리십시오. –
JSON에 "속성"값이 있고 속성에 "이름"과 "나이"만 들어 있습니다. JSON에서 속성을 제거해야합니다. '{ "name": "name", "age": "22"}' –