I have some JSON I would like to map to my Boxobject:
{
"created_date": "2015-11-11",
"generation_date": "2015-11-12T20:35:00+0000",
"values": {
"MORNING": 13,
"EVENING": 18,
"NOON": 446,
"NIGHT": "0.60.0"
},
"id": "12345"
}
And my Box object looks like:
public class Box {
@JsonProperty
Map<String, Object> json;
public Box() {
// Blank
}
// Getter and setter for `json` field
}
This is the code I have:
Box box = null;
// `JSON_STRING` below refers to a string of the above JSON
metricsPacket = new ObjectMapper().readValue(JSON_STRING, Box.class);
I keep getting this error:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "created_date" (class com.me.Box), not marked as ignorable (one known property: "json"])
All of the examples I've found online are just deserializing JSON to a simple POJO with a handful of String or int member variables. How can I properly map my JSON to my json field and have it behave correctly?
I'd imagine that once this works json.get("id") would return 12345 while json.get("values") would return another Map<String, Object> (or Map<String, String>). I'm still new to using Jackson, so this also might not even be the right way to do what I want to do. Any help would be appreciated!