Problem with org.codehaus.jackson.map.ObjectMapper
This ties to my other question here, in which I had issues with deserializing object using RestTemplate. I thought of deserializing the object myself using org.codehaus.jackson.map.ObjectMapper which RestTemplate internally uses. I am still not able deserialize using org.codehaus.jackson.map.ObjectMapper. However interestingly, I am able to deserialize it successfully using com.fasterxml.jackson.databind.ObjectMapper. This explains why RestTemplate is failing to deserialize?
The JSON response looks like,
Code:
{
"response": {
"Time": "Wed 2013.01.23 at 03:35:25 PM UTC",
"Total_Input_Records": 5,
},-
"message": "Succeeded",
"code": "200"
}
Converted this Json payload into a POJO using jsonschema2pojo
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 deserialization code,
Code:
String jsonStr = "{\"response\": {"
+ "\"Time\": \"Wed 2013.01.23 at 03:35:25 PM UTC\","
+ "\"Total_Input_Records\": \"5\"},"
+ "\"message\": \"Succeeded\"," + "\"code\": \"200\"" + "}";
ObjectMapper mapper = new ObjectMapper();
MyClass wrapper mapper.readValue(jsonStr, MyClass.class);
Below is the exception I get with org.codehaus.jackson.map.ObjectMapper[/CODE]. Again, this exact code WORKS with com.fasterxml.jackson.databind.ObjectMapper
Code:
org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "Time" (Class com.temp.pointtests.Response), not marked as ignorable
at [Source: java.io.StringReader@2c9b42e6; line: 1, column: 24] (through reference chain: MyClass["response"]->Response["Time"])