【发布时间】:2019-12-17 14:22:51
【问题描述】:
public static Object convertToObject(String json) {
validate("json", json);
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.readValue(json, new TypeReference<Object>(){});
} catch (JsonProcessingException ex) {
throw new RuntimeException("Failed to convert json to object: "+json, ex);
}
}
//Here I'm doing type cast for the returned object
Map<String, ArrayList<Integer>> convertedMap = (Map<String, ArrayList<Integer>>) RestClient.convertToObject(json);
我试过上面的代码 我正在使用杰克逊,我需要传递带有类型的 json,这样我就可以避免在调用者位置进行类型转换。
谁能帮我解决这个问题?
提前致谢
【问题讨论】:
标签: java json generics casting