方式一:
String jsonList = "[{'beanId':'1','beanName':'jack'},{'beanId':'2','beanName':'rose'}]";
ObjectMapper mapper = new ObjectMapper();
//如果是List类型
JavaType javaType = mapper.getTypeFactory().constructParametricType(List.class, Bean.class);
//如果是Map类型
JavaType javaType = mapper.getTypeFactory().constructParametricType(HashMap.class,String.class, Bean.class);
List<Bean> list = (List<Bean>)mapper.readValue(jsonList, javaType);
方式二:
String jsonList = "[{'beanId':'1','beanName':'jack'},{'beanId':'2','beanName':'rose'}]";
ObjectMapper mapper = new ObjectMapper();
List<Bean> beanList = mapper.readValue(jsonList, new TypeReference<List<Bean>>() {});
List<Bean> beanList = mapper.readValue(jsonList, new TypeReference<Map<String,Object>>() {});
想要更多的了解可以参考:
http://www.mkyong.com/java/jackson-2-convert-java-object-to-from-json/