Bleow是必须通过使用Spring Rest模板转换为对象的json。Spring RestTemplate的JSON反序列化问题
{"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)
请提供一些意见以解决问题。
你的'Registration'类是什么样的? –