Jackson反序列化泛型List

ObjectMapper mapper = new ObjectMapper();
String json = "[{\"name\":\"a\",\"password\":\"345\"},{\"name\":\"b\",\"password\":\"123\"}]";
        
//第一种方法
List<User> list = mapper.readValue(json, new TypeReference<List<User>>(){/**/});
        
//第二种方法
JavaType javaType = mapper.getTypeFactory().constructCollectionType(List.class, User.class);
List<User> list2 = mapper.readValue(json, javaType);

 

posted @ 2015-07-21 15:58  cyberghost  阅读(2114)  评论(0编辑  收藏  举报