Jackson 处理复杂类型(List,map)两种方法

http://blog.csdn.net/zhuyijian135757/article/details/38269715

——————————————————————————————————————————

方法一:

  1. String jsonString="[{'id':'1'},{'id':'2'}]";  
  2. ObjectMapper mapper = new ObjectMapper();  
  3. JavaType javaType = mapper.getTypeFactory().constructParametricType(List.class, Bean.class);  
  4. //如果是Map类型  mapper.getTypeFactory().constructParametricType(HashMap.class,String.class, Bean.class);  
  5. List<Bean> lst =  (List<Bean>)mapper.readValue(jsonString, javaType);   


方法二:

    1. String jsonString="[{'id':'1'},{'id':'2'}]";  
    2. ObjectMapper mapper = new ObjectMapper();  
    3. List<Bean> beanList = mapper.readValue(jsonString, new TypeReference<List<Bean>>() {});  
原文地址:https://www.cnblogs.com/cuizhf/p/5684585.html