Bleow는 Spring Rest Template을 사용하여 객체로 변환해야하는 json입니다.JSON Spring RestTemplate에 대한 비 직렬화 문제
{"userResponse": {
"build": 1,
"code": 400,
"status": "Failed",
"validationErrors": [
{
"fieldName": "userId",
"message": "User Id is NOT in valid format"
},
{
"fieldName": "password",
"message": "Password cannot be less than 8 characters"
}
]
}}
여기 validationErrors에 대한 요소 목록이 응답의 일부인 경우 문제가 발생합니다.
아래는 스프링 나머지 템플릿 구성입니다.
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" >
<property name="supportedMediaTypes" value="application/json" />
</bean>
</list>
</property>
</bean>
다음은 postForObject를 호출하기위한 코드입니다. 서비스를 호출하는 동안
restTemplate.postForObject("ServiceUrl", "userinput", Registration.class);
다음은 오류 던지고있다.
org.springframework.web.client.HttpClientErrorException: 400 Bad Request
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:90)
at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:494)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:451)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:409)
일부 입력 사항을 제공하여 문제를 해결하십시오.
'등록'클래스는 무엇입니까? –