How to use Jackson to deserialise an array of objects

first create a mapper :java

import com.fasterxml.jackson.databind.ObjectMapper; ObjectMapper mapper = new ObjectMapper();

As Array:json

MyClass[] myObjects = mapper.readValue(json, MyClass[].class);

As List:app

List<MyClass> myObjects = mapper.readValue(jsonInput, new com.fasterxml.jackson.core.type.TypeReference<List<MyClass>>(){});

Another way to specify the List type:spa

List<MyClass> myObjects = mapper.readValue(jsonInput, mapper.getTypeFactory().constructCollectionType(List.class, MyClass.class));
相關文章
相關標籤/搜索