I have a JSON file which can have multiple types.
For example:
{
"dog": {
"owner" : "John Smith",
"name" : "Rex",
"toys" : {
"chewtoy" : "5",
"bone" : "1"
}
},
"person": {
"name" : "John Doe",
"address" : "23 Somewhere Lane"
}
// Further examples of dogs and people, and a few other types.
}
I want to parse these into objects. ie. I want to create a Dog object with owner/name/toys attributes, and person with name/address attributes, and use Jackson to read through and create objects out of them.
The ordering matters - I need to know that Rex came before John Doe, for example. I would prefer to do with a stream like approach (ie. read and parse Rex into the Dog object, do something with it, then discard it, then move onto to John Doe). So I need a stream based approach.
I can't figure out how to use both the stream reading API (to go through in order) and the ObjectMapper interface (in order to create Java objects out of JSON) to accomplish this.