嗨,我正在使用 Spring rest Template 来访问 POST API,它工作得非常好。
问题是当我将它与 MockRestServiceServer 一起使用时。
我创建了一个 MockRestServiceServer 实例:
mockServer = MockRestServiceServer.createServer(restTemplate);
并添加了预期的请求 URL 和响应,即:
mockServer.expect(requestTo(URL)).andExpect(method(HttpMethod.POST))
.andRespond(withSuccess(Response,MediaType.APPLICATION_JSON));
当我尝试使用 JSON 正文点击特定的 POST URL 时
{"AppName":{"Value":"Google"}}
我收到错误
org.springframework.http.converter.HttpMessageNotReadableException:
Could not read JSON: Unexpected character ('A' (code 65)): was expecting double-quote
to start field name at
[Source: java.io.ByteArrayInputStream@5473b9e; line: 1, column: 3];
nested exception is org.codehaus.jackson.JsonParseException: Unexpected character
('A' (code 65)): was expecting double-quote to start field name at
[Source: java.io.ByteArrayInputStream@5473b9e; line: 1, column: 3] at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.readInternal
(MappingJacksonHttpMessageConverter.java:127) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE] at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:153) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:81) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:446) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:279) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
谁能帮助我我在这里缺少什么?