Jackson将json字符串转换成泛型List,Map
需要先反序列化复杂类型 为泛型的Collection Type
如果是ArrayList<YourBean>那么使用ObjectMapper 的getTypeFactory().constructParametricType(ArrayList.class, YourBean.class);
ObjectMapper mapper = new ObjectMapper(); JavaType javaType = mapper.getTypeFactory().constructCollectionType(ArrayList.class, YourBean.class)); List<YourBean> lst = (List<YourBean>)mapper.readValue(jsonString, javaType);
如果是HashMap<String,YourBean>那么 ObjectMapper 的getTypeFactory().constructParametricType(HashMap.class,String.class, YourBean.class);
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。