I am using RestTemplate and having issues deserializing an object. Here is what I am doing. The JSON response looks like,
Converted this Json payload into a POJO using jsonschema2pojoCode:{ "response": { "Time": "Wed 2013.01.23 at 03:35:25 PM UTC", "Total_Input_Records": 5, },- "message": "Succeeded", "code": "200" }
Here is the request processing where I am getting the exception,Code:public class MyClass { @JsonProperty("response") private Response response; @JsonProperty("message") private Object message; @JsonProperty("code") private Object code; private Map<String, Object> additionalProperties = new HashMap<String, Object>(); //bunch of getters and setters here } public class Response { @JsonProperty("Time") private Date Time; @JsonProperty("Total_Input_Records") private Object Total_Input_Records; private Map<String, Object> additionalProperties = new HashMap<String, Object>(); //bunch of getters and setters here }
Here is the frustrating part, exception (deliberately trimmed, not full). Anything I am missing?Code:tring url = "http://my.site.com/someparams"; RestTemplate template = new RestTemplate( new HttpComponentsClientHttpRequestFactory()); FormHttpMessageConverter converter = new FormHttpMessageConverter(); List<MediaType> mediaTypes = new ArrayList<MediaType>(); mediaTypes.add(new MediaType("application", "x-www-form-urlencoded")); converter.setSupportedMediaTypes(mediaTypes); template.getMessageConverters().add(converter); MyClass upload = template.postForObject(url, null, MyClass.class);
Code:org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Unrecognized field "Time" (Class com.temp.pointtests.Response), not marked as ignorable at [Source: org.apache.http.conn.EofSensorInputStream@340ae1cf; line: 1, column: 22 (through reference chain: com.temp.pointtests.MyClass["response"]->com.temp.pointtests.Response["Time"]);]


Reply With Quote
