Jackson将json字符串转换成泛型List/map
url: http://www.cnblogs.com/quanyongan/archive/2013/04/16/3024993.html
Jackson处理一般的JavaBean和Json之间的转换只要使用ObjectMapper 对象的readValue和writeValueAsString两个方法就能实现。但是如果要转换复杂类型Collection如 List
如果是ArrayList
如果是HashMap
public final ObjectMapper mapper = new ObjectMapper();
public static void main(String[] args) throws Exception{
JavaType javaType = getCollectionType(ArrayList.class, YourBean.class);
List
}
/**
* 获取泛型的Collection Type
* @param collectionClass 泛型的Collection
* @param elementClasses 元素类
* @return JavaType Java类型
* @since 1.0
*/
public static JavaType getCollectionType(Class> collectionClass, Class>... elementClasses) {
return mapper.getTypeFactory().constructParametricType(collectionClass, elementClasses);
}