简体   繁体   English

转换JSON响应时找不到合适的HttpMessageConverter?

[英]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.

相关问题 没有找到适合响应类型的 HttpMessageConverter - no suitable HttpMessageConverter found for response type 找不到适用于响应类型[..]和内容类型[application / json]的HttpMessageConverter - No suitable HttpMessageConverter found for response type [..] and content type [application/json] 无法提取响应:找不到合适的HttpMessageConverter - Could not extract response: no suitable HttpMessageConverter found 没有为响应类型找到合适的HttpMessageConverter - Custom RestTemplate - No suitable HttpMessageConverter found for response type - Custom RestTemplate 找不到适合响应类型和内容类型的HttpMessageConverter - no suitable HttpMessageConverter found for response type and content type 没有找到适合响应类型和内容类型的 HttpMessageConverter [application/json;charset=UTF-8] 发生异常 - No suitable HttpMessageConverter found for response type and content type [application/json;charset=UTF-8] exception occurs Android版Spring-无法提取响应:找不到适合响应类型的HttpMessageConverter - Spring for Android - Could not extract response: no suitable HttpMessageConverter found for response type RestClientException无法提取响应:找不到合适的HttpMessageConverter作为响应类型 - RestClientException Could not extract response: no suitable HttpMessageConverter found for response type 休息模板:无法提取响应:当我们得到 xml 响应时,没有找到适合响应类型的 HttpMessageConverter,未绑定到 JAVA 对象 - Rest Template:Could not extract response: no suitable HttpMessageConverter found for response type when we got xml response, not bind to JAVA object 尝试执行restclient请求时找不到合适的HttpMessageConverter - No suitable HttpMessageConverter found when trying to execute restclient request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM