Reputation: 175
I am hitting a service to find the details of a person, the response is in xml format like the following:
<ArrayOfPersonResults xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<PersonResults>
<Name>John Doe</Name>
<State>NY</State>
<Zip>12345</Zip>
</PersonResults>
</ArrayOfPersonResults>
I am making use of Spring RestTempate and mapping the response to the following POJOs,
public class Person {
private String zip;
private String name;
private String state;
public String getZip() {
return zip;
}
@JsonProperty("Zip")
public void setZip(String zip) {
this.zip = zip;
}
public String getName() {
return name;
}
@JsonProperty("Name")
public void setName(String name) {
this.name = name;
}
public String getState() {
return state;
}
@JsonProperty("State")
public void setState(String state) {
this.state = state;
}
}
I invoke the service using rest template,
public Person[] getPersosn(String personId) {
try {
return getRestTemplate().getForObject(personServiceURL, Person[].class, personId);
} catch (Exception e) {
return null;
}
}
But I keep getting the exception, org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class [Lcom.cdk.dataloader.model.Person;] and content type [application/json;charset=utf-8]
I am not sure why I am getting this, any help appreciated.
Upvotes: 0
Views: 1639
Reputation: 57381
Your content type is application/json;charset=utf-8
but you got XML. Chanage the content to JSON or change content type to be one of text/xml, application/xml
Upvotes: 1