0 0

用spring rest客户端 restTemplate.postForObject(serverUrl, map, String.class)0

我在客户端用spring rest客户端 restTemplate.postForObject(serverUrl, map, String.class)请求,map中的参数被序列化为JSON格式,如下:
{"format":"json","id":"1","address":"{\"zoneCode\":\"10000\",\"doorCode\":\"20000\",\"streets\":[{\"no\":\"111\",\"name\":\"abc\"}],"name":"wgw","pass":"123"},在服务端做转换时,spring用的是jackson,代码如下
@RequestMapping(value = "/", method = RequestMethod.POST)
public Result getUser(@RequestBody User user) {
User user1 = new User();
user1.setId(1l);
user1.setName("www");
             }
其中User有一个复合属性Address,始终报org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not instantiate value of type [simple type, class com.mms.cod.controller.Address] from String value ('{"zoneCode":"10000","doorCode":"20000","streets":[{"no":"111","name":"abc"}],"codes":["a","b"]}'); no single-String constructor/factory method (through reference chain: com.mms.cod.controller.User["address"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class com.mms.cod.controller.Address] from String value ('{"zoneCode":"10000","doorCode":"20000","streets":[{"no":"111","name":"abc"}],"codes":["a","b"]}'); no single-String constructor/factory method (through reference chain: com.mms.cod.controller.User["address"]),求帮助
2014年6月09日 09:37
目前还没有答案

相关推荐

Global site tag (gtag.js) - Google Analytics