Hi all,
I'm encountering an issue where my deserialization fails. I'm not sure if it is Spring-related, Jackson-related, or my own POJO/JSON mapping, but let me describe the details below.
The error message is:
Below is the sample JSON string to deserialize (notice the Pascal case for the property names):Code:I/O error: Can not deserialize instance of co.test.location.status.Request[] out of START_OBJECT token at [Source: org.apache.http.conn.EofSensorInputStream@45ce7738; line: 1, column: 1]
Below is the POJO to represent the JSON data:Code:{"Category":"Test","DateClosed":"","DateInitiated":"3\/20\/2011","Description":"","FullAddress":"2301 COURTKING DR","Intersection":"COURTKING DR AND HENDERSON PL","QuestionAndAnswers":[{"Answer":"Depends on the sign","Question":"Is this Deliverable?"}],"RequestType":"Deliver Type","ServiceRequestNumber":"213-375001","Status":"Open","SubRequestType":"Sign Visibility"}
The fail call is via Spring's RestTemplate:Code:public class Request { @JsonProperty("Category") private String category; @JsonProperty("ServiceRequestNumber") private String serviceRequestNumber; @JsonProperty("Status") private String status; @JsonProperty("DateInitiated") private Date dateInitiated; @JsonProperty("DateClosed") private Date dateClosed; @JsonProperty("RequestType") private String requestType; @JsonProperty("SubRequestType") private String subRequestType; @JsonProperty("FullAddress") private String fullAddress; @JsonProperty("Description") private String description; @JsonProperty("Intersection") private String intersection; @JsonProperty("QuestionAndAnswers") private List<QuestionAndAnswers> questionAndAnswers = new ArrayList<QuestionAndAnswers>(); ... ... // getters and setters // static inner class public static class QuestionAndAnswers { @JsonProperty("Question") private String question; @JsonProperty("Answer") private String answer; // getters and setters }
Code:RestTemplate restTemplate = new RestTemplate(); List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>(); messageConverters.add(new FormHttpMessageConverter()); messageConverters.add(new StringHttpMessageConverter()); messageConverters.add(new MappingJacksonHttpMessageConverter()); restTemplate.setMessageConverters(messageConverters); ResponseEntity<Request[]> responseEntity = restTemplate.exchange(url, HttpMethod.GET, createHttpRequestEntity(), Request[].class);
My hunch is the POJO is incorrectly defined. Because of the first letter uppercasing in the JSON properties, I had to add the @JsonProperty annotations to make the conversion. Not sure if this is the right way or not.
Any help would be appreciated. Thanks.
-los


Reply With Quote