把整个List当做泛型,是否也可以不传入TypeReference
来源:1-4 更简单的泛型反序列化方法(3)
BiGToom
2020-04-18 15:58:44
public static <T> T jsonToObject(String s){
if(s==null){
return null;
}
try {
T o = GenericAndJson.mapper.readValue(s, new TypeReference<T>() {});
return o;
} catch (JsonProcessingException e) {
e.printStackTrace();
throw new ServerErrorException(9999);
}
}
看到同样的提问了,但是老师的回答说得到的是HashMap我是没看到,我看到的是得到了ArrayList呢?好像是推断正确了。
1回答
BiGToom
提问者
2020-04-18
看到HashMap了,两种方式返回的都是HashMap,而不是强类型Spec对象
相似问题
回答 1