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);
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。