The Jackson data binding documentation indicates that Jackson supports deserialising "Arrays of all supported types" but I can't figure out the exact syntax for this.
For a single object I would do this:
//json input
{
"id" : "junk",
"stuff" : "things"
}
//Java
MyClass instance = objectMapper.readValue(json, MyClass.class);
Now for an array I want to do this:
//json input
[{
"id" : "junk",
"stuff" : "things"
},
{
"id" : "spam",
"stuff" : "eggs"
}]
//Java
List<MyClass> entries = ?
Anyone know if there is a magic missing command? If not then what is the solution?
First create a mapper :
As Array:
As List:
Another way to specify the List type:
For Generic Implementation:
From Eugene Tskhovrebov
This solution seems to be the best for me
First create an instance of ObjectReader which is thread-safe.
Then use it :
here is an utility which is up to transform json2object or Object2json, whatever your pojo (entity T)