我具有String以下值:
String
[ { "key1": "value11", "key2": "value12" }, { "key1": "value21", "key2": "value22" } ]
和以下类:
public class SomeClass { private String key1; private String key2; /* ... getters and setters omitted ...*/ }
我想将其解析为a List<SomeClass>或aSomeClass[]
List<SomeClass>
SomeClass[]
使用Jackson的 方法最简单ObjectMapper?
ObjectMapper
我终于明白了:
ObjectMapper objectMapper = new ObjectMapper(); TypeFactory typeFactory = objectMapper.getTypeFactory(); List<SomeClass> someClassList = objectMapper.readValue(jsonString, typeFactory.constructCollectionType(List.class, SomeClass.class));