[英]No suitable HttpMessageConverter found when converting JSON response?
I'm getting a simple json
response and wanted to map it as follows to a pojo: 我得到一个简单的
json
响应,并想将其映射为pojo如下:
ResponseEntity<JsonEntity> response = new RestTemplate().getForEntity(url, JsonEntity.class);
@JsonIgnoreProperties(ignoreUnknown = true)
public class JsonEntity {
//@JsonProperty getter + setter...
}
But I'm just getting the following exception. 但是我得到以下异常。 What might be missing?
可能缺少什么?
org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class JsonEntity] and content type [application/octet-stream]
org.springframework.web.client.RestClientException:无法提取响应:未为响应类型[class JsonEntity]和内容类型[application / octet-stream]找到合适的HttpMessageConverter
For the default JSON HttpMessageConverter
, you'll need to add either Jackson 1 or Jackson 2 to your classpath. 对于默认的JSON
HttpMessageConverter
,您需要将Jackson 1或Jackson 2添加到您的类路径中。
Otherwise, you can add some other JSON library and write your own HttpMessageConverter
which can do the deserialization. 否则,您可以添加其他一些JSON库并编写自己的
HttpMessageConverter
来进行反序列化。
事实证明,该服务未使用UTF-8
编码进行响应,而是ISO 8859-1
,由于杰克逊解析器只能手动使用utf-8,导致了错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.