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

相关推荐

    RestTemplate如何在Spring或非Spring环境下使用.docx

    String str = restTemplate.getForObject(url, String.class); System.out.println(str); } ``` 在非Spring环境下,可以直接引用`spring-web`模块来使用`RestTemplate`,无需整个Spring框架。只需在Maven或Gradle...

    spring-mock.jar

    org.springframework.mock.jndi.ExpectedLookupTemplate.class org.springframework.mock.jndi.SimpleNamingContext.class org.springframework.mock.jndi.SimpleNamingContextBuilder.class org.springframework....

    spring rest mvc使用RestTemplate调用

    ResponseEntity<String> response = restTemplate.getForEntity(url, String.class); ``` - **POST请求**:使用`postForEntity()`,传入URL、请求体和响应类型。例如,发送JSON数据: ```java ...

    在原生Android应用中支持Spring的RestTemplate.zip

    RestTemplate是一个便捷的REST客户端,它能够帮助开发者简化客户端对RESTful服务的访问。 在本项目中,开发者可以通过对RestTemplate的使用,将Android应用与Spring框架所提供的RESTful服务进行连接。这将使得...

    resttemplate multipartfile.pdf

    restTemplate.postForObject(url, entity, String.class); } ``` 其中,url 表示上传文件的服务端地址,file 表示要上传的文件。在这个示例中,我们首先创建了一个 RestTemplate 对象,并设置了 HttpHeaders 的 ...

    spring-struts.jar

    META-INF/MANIFEST.MForg.springframework.web.struts.ActionServletAwareProcessor.class org.springframework.web.struts.ActionSupport.class org.springframework.web.struts.AutowiringRequestProcessor.class ...

    RestTemplate例子

    - GET:获取资源,例如`ResponseEntity<String> result = restTemplate.getForObject(url, String.class);` - POST:提交数据,例如`restTemplate.postForEntity(url, new HttpEntity<>(requestBody), ...

    02_SpringCloud客户端负载均衡Ribbon.md

    return restTemplate.getForObject(serverurl,String.class); } private Integer requestCount = 1; @RequestMapping("/getServerurl") public String getServerurl(){ List<ServiceInstance> ...

    精讲RestTemplate文件上传下载与大文件流式下载.docx

    String result = restTemplate.postForObject(url, param, String.class); System.out.println("---访问地址:" + result); } } ``` ### 二、文件下载 文件下载可以通过`RestTemplate`的`getForEntity`方法实现...

    Spring使用RestTemplate模拟form提交示例

    String result = restTemplate.postForObject("http://....",entity,String.class); return result; } } ``` 在上面的代码中,我们首先注入了 RestTemplate,然后设置了请求头和提交参数。最后,我们使用 ...

    精讲RestTemplate,POST请求方法使用详解.docx

    String result = restTemplate.postForObject(url, request, String.class); System.out.println(result); } ``` **分析**: 1. **请求头**:设置为 `MediaType.APPLICATION_FORM_URLENCODED` 表示表单数据。 2. ...

    RestTemplate的GET方法详解.docx

    - **以String方式接收**:调用`restTemplate.getForObject(url, String.class)`,将响应体转换为String类型。 - **以POJO对象方式接收**:通过`restTemplate.getForObject(url, PostDTO.class)`,将响应体转换为...

    spring-android-rest-template-1.0.1.RELEASE.jar.zip

    ResponseEntity<MyResponse> response = restTemplate.getForEntity(url, MyResponse.class); ``` **4. 示例应用** 假设有一个RESTful API,用于获取用户信息,接口为`GET /api/users/{userId}`,返回JSON格式的...

    Spring cloud restTemplate 传递复杂参数的方式(多个对象)

    restTemplate.postForObject("http://service-a/import/" + busiCode + "/" + filePath, params, Map.class); // ... } } ``` 在上面的代码中,我们使用 RestTemplate 的 postForObject 方法来调用服务 A,并传递...

    org.springframework.web.servlet-3.0.1.RELEASE-A.jar

    Error creating bean with name 'org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0' defined in ServletContext resource [/WEB-INF/springMVC-servlet.xml]: Initialization of bean failed;...

    org.springframework.web的jar包.zip

    《Spring框架Web模块详解——聚焦于WebSocket服务器端点支持》 在Java开发领域,Spring框架以其强大的功能和灵活的设计闻名,而`org.springframework.web`包是Spring框架中的一个重要部分,它提供了处理HTTP请求和...

    org.spring-framework-3.0.4. 所有jar

    org.springframework.aop-3.0.4.RELEASE.jar org.springframework.asm-3.0.4.RELEASE.jar org.springframework.aspects-3.0.4.RELEASE.jar org.springframework.beans-3.0.4.RELEASE.jar org.springframework....

    使用Rest Assured和Mockmvc进行Spring mvc集成测试.zip

    这些测试可能包含了`@RunWith(SpringRunner.class)`和`@SpringBootTest`注解来启动Spring测试环境,以及`@Autowired`注解来注入`MockMvc`实例。 5. **Mock对象**:在测试中,可能会用到`@MockBean`或`@SpyBean`注解...

    详解使用Spring的restTemplete进行Http请求

    String result = restTemplate.postForObject(url, formEntity, String.class); ``` 四、自定义 RestTemplate RestTemplate 提供了许多自定义选项,例如设置连接超时、读取超时、最大连接数等。例如: ```java ...

    RestTemplate的使用及需要注意的地方

    ResponseEntity<String> response = restTemplate.getForEntity(url, String.class); ``` 3. **发送POST请求**: 对于POST请求,我们通常需要传递请求体。这可以通过`HttpEntity`对象完成: ```java ...

Global site tag (gtag.js) - Google Analytics