将Json数组反序列化为对象列表

时间:2019-12-03 10:50:43

标签: java json mapstruct

我有一个json字符串,实际上是json对象的数组,我想使用objectMapper将其反序列化为对象列表。我该如何实现?

目前我是这样的:

private ObjectMapper objectMapper = new ObjectMapper();

List<Event> events = readValue(jsonString, MyObject.class);

1 个答案:

答案 0 :(得分:1)

尝试一下:

private ObjectMapper objectMapper = new ObjectMapper();

List<Event> events = objectMapper.readValue(jsonString, new TypeReference<List<MyObject>>() {});