Question:
How to deserializing arrays of objects into a Java list using Jackson?
Solution:
import com.fasterxml.jackson.databind.ObjectMapper; ObjectMapper mapper = new ObjectMapper();
// JSON Input: [{...}, {...}, ...] MyClass[] myObjects = mapper.readValue(json, MyClass[].class);
List<MyClass> myObjects = mapper.readValue(jsonInput, new TypeReference<List<MyClass>>() {});
List<MyClass> myObjects = mapper.readValue(jsonInput, mapper.getTypeFactory().constructCollectionType(List.class, MyClass.class));
The above is the detailed content of How to Deserialize JSON Arrays of Objects into Java Lists using Jackson?. For more information, please follow other related articles on the PHP Chinese website!