I have below JSON which I want to parse into below bean classes.
{
"timeStamp": "123123123123",
"pznFlowFlag": "true",
"pznRequestFlag": "true",
"sessionId": "SampleSessionId",
"ipAddress": "172.148.0.1",
"offers": [
{
"111": {
"eep" : "44279",
"spl_ind" : "true"},
"121": {
"eep" : "44520",
"spl_ind" : "false"},
"333": {
"eep" : "45419",
"spl_ind" : "false" }
}]
}
Bean class 1
public class DistributedCookieBean {
@JsonProperty("timeStamp")
private String timeStamp;
@JsonProperty("pznFlowFlag")
private String pznFlowFlag;
@JsonProperty("pznRequestFlag")
private String pznRequestFlag;
@JsonProperty("sessionId")
private String sessionId;
@JsonProperty("ipAddress")
private String ipAddress;
@JsonProperty("offers")
private Map<String, OfferCookieBean> offers = new HashMap<String, OfferCookieBean>();
...<setters & getters>
}
Bean class 2
public class OfferCookieBean {
@JsonProperty("eep")
private String eep;
@JsonProperty("spl_ind")
private String spl_ind;
...<setters & getters>
}
Here I am not able to parse into the these Java POJOs using below code.
jsonObjMapper.readValue(jsonString, DistributedCookieBean.class);
Stacktrace:
org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.Map out of START_ARRAY token at [Source: json.txt; line: 6, column: 31] at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:159) at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:192) at org.codehaus.jackson.map.deser.MapDeserializer.deserialize(MapDeserializer.java:134) at org.codehaus.jackson.map.deser.MapDeserializer.deserialize(MapDeserializer.java:23) at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:135) at org.codehaus.jackson.map.deser.SettableBeanProperty$MethodProperty.deserializeAndSet(SettableBeanProperty.java:221) at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:391) at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:287) at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:1588) at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1074) at Test.main(Test.java:29)
Thanks in advance!