Posting the question as I can't find solution specific to below problem.
One of the 3rd part REST service we are consuming return response similar to
{ "_id": "d55eb7c0", "applicationType": "TEST", "applicationId": "uxhJ1hcT1F8bpL3xAWvTjsymNcd1RArv", "description": "Some Description"}
tried to map "_id" attribute as, to follow proper java bean naming
@JsonProperty("_id")
private String id;
which results in following error.
org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class ] and content type [application/json;charset=utf-8]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:109)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:917)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:901)
if the field name is private String _id;
json response is de-serialised without any issue. but I don't want to name field starting with '_' in our app. We are using Jackson-2.7.3 & Spring RestTemplate to make REST calls.
Implementation for consuming the endpoint. Its a simple GET call using Spring RestTemplate.
HttpEntity<String> requestEntity = new HttpEntity<>(httpHeaders); return restTemplate.exchange(authorizationProperties.getEndpoint() + "/roles", HttpMethod.GET, requestEntity,new ParameterizedTypeReference<Auth0Roles>() {});
Thanks in advance.
I guess you need to apply the annotation on the accessor methods, not the field itself:
private String id;
@JsonProperty("_id")
public String getId() {
return this.id;
}
public void setId(String i) {
this.id = i;
}
Its not looking like the problem with JSON. Most probably you are missing the HttpMessageConverter.
Try Adding this dependency
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.3</version>
</dependency>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.