I have a Json file that looks like this:
[
{ "field":"val" },
....
]
I have Java object representing single object and collection of them:
public class Objects{
public Collection<List> myObject;
}
I would like to deserialize JSON using ObjectMapper.
ObjectMapper mapper = new ObjectMapper();
mapper.readValue(in, Objects.class);
But I get:
11-24 23:19:19.828: W/UpdateService(6084): org.codehaus.jackson.map.JsonMappingException:
Can not deserialize instance of com.project.my.Objects out of START_ARRAY token
Try
Where ObjectClass is something like:
Note: in your posted version of the
Objectsclass, you’re declaring a Collection of Lists (i.e. a list of lists), which is not what you want. You probably wanted aList<ObjectClass>. However, it’s much simpler to just doYourObject[].classwhen deserializing with Jackson, and then converting into a list afterwards.