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
目前还没有答案

相关推荐

    SpringBoot整合hive-jdbc示例

    public List<Map<String, Object>> query(String sql) { return jdbcTemplate.queryForList(sql); } } ``` 这里我们使用了Spring的`JdbcTemplate`,它简化了数据库操作,提供了执行SQL语句和处理结果的方法。 #...

    spring 整合jersey最新的所有jar

    在指定的包或类中,你可以创建Java类来表示REST资源,这些类通常会使用JSR 311或JAX-RS注解(如`@Path`, `@GET`, `@POST`, `@QueryParam`等)来定义路由和处理方法。 例如: ```java @Path("/hello") public class...

    spring-cloud 集成 flowable 工作流

    public void startProcessInstanceByKey(String processDefinitionKey, Map<String, Object> variables) { runtimeService.startProcessInstanceByKey(processDefinitionKey, variables); } // 其他方法... } ``...

    java Jersey Rest

    private Map<String, String> map = new HashMap(); public HelloWorldRS() { map.put("1", "A"); map.put("2", "B"); map.put("3", "C"); } @GET @Path("/sayHelloByGET") @Produces(MediaType.TEXT_...

    SpringBoot学习之路—SpringBoot整合SpringCloud(Eureka&服务提供和消费)

    在Spring Boot的学习过程中,整合Spring Cloud Eureka是一个重要的步骤,因为Eureka是Spring Cloud生态中的核心组件之一,它主要用于实现服务发现和管理。本篇文章将详细介绍如何将Spring Boot应用程序与Eureka结合...

    Springboot+maven+idea+mysql实战之获取数据库信息显示在前端

    在本教程中,我们将探讨如何使用Spring Boot、Maven、IntelliJ IDEA和MySQL数据库创建一个实战项目,目的是从数据库获取信息并在前端展示。首先,我们需要确保我们的开发环境已准备就绪,包括安装IntelliJ IDEA作为...

Global site tag (gtag.js) - Google Analytics