Jackson 處理復雜類型(List,map)兩種方法


 

方法一:

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

 

方法二:

String jsonString="[{'id':'1'},{'id':'2'}]";  
ObjectMapper mapper = new ObjectMapper();  
List<Bean> beanList = mapper.readValue(jsonString, new TypeReference<List<Bean>>() {});   

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM