【发布时间】:2019-02-24 13:51:07
【问题描述】:
我有一个 json 字符串,它是字符串列表的列表,需要将其转换为 List<List<String>> 类的对象。
Here 它说明了如何从字符串转换为列表,但它对我不起作用,因为我无法在 constructCollectionType 中指定 List<List<String>> 类
这是我的尝试,但不起作用:
ObjectMapper objectMapper = new ObjectMapper();
TypeFactory typeFactory = objectMapper.getTypeFactory();
List<List<String>> list = objectMapper.readValue(response,
typeFactory.constructCollectionType(List.class, List.class));
如何做到这一点?
【问题讨论】:
-
您使用哪个版本的
Jackson?我测试了它的最新版本,它工作正常。