有没有办法强制RestTemplate对特定的消息使用特定的HttpMessageConverter?
由于某种原因,我发送了一个对象作为有效负载,即使注释是Json的(@JsonCreator,XML...),它也使用MappingJackson2XmlHttpMessageConverter将该对象序列化为@JsonProperty。
发布于 2016-02-10 06:04:37
更改为restClient.exchange并将Content-Type header设置为application/json,以便在JSON中显式请求响应。
LoginRequestType<XXXX> loginRequest;
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<LoginRequestType<XXXX>> requestEntity = new HttpEntity<LoginRequestType<XXXX>>(loginRequest,headers);
Response<EmptyData> response = restClient
.exchange("https://" + deviceIP + "/jsonrpc",
HttpMethod.POST,
requestEntity,
new ParameterizedTypeReference<Response<EmptyData>>(){}).getBody();https://stackoverflow.com/questions/35300157
复制相似问题