Using Jackson how do I parse the following JSON:
{
"foos" : [
"one" : {
"prop1" : "11",
"prop2" : "11"
},
"two" : {
"prop1" : "21",
"prop2" : "21"
},
"three",
"four"
]
}
Into these classes:
public class Root {
private Set<Foo> foos;
// ... getter and setter
}
public class Foo {
private String name; // this should contain the JSON name, e.g.: "one", "two", "three"
private String prop1;
private String prop2;
// ... getters and setters
}
Regarding the JSON, I prefer to have named objects rather than:
"foos" : [
{
"name" : "one",
"prop1" : "11",
"prop2" : "11"
},
{
"name" : "two",
"prop1" : "21",
"prop2" : "21"
},
{
"name" : "three"
},
{
"name" : "four"
}
]
Because most of the foos contain no other properties, I don't know if the first JSON is less correct but it is more succinct.