我正在尝试加载从 JSON 文件获取的值。 重新加载JSON文件的目标对象是:
HashMap<String,LinkedList<Investor>> investors_per_location=new HashMap<>();
我正在做的是创建几种类型:
MapType mapType = null;
CollectionType mapTypeAux = null;
mapTypeAux = typeFactory.constructCollectionType(LinkedList.class,Investor.class);
mapType = typeFactory.constructMapType(HashMap.class, String.class,mapTypeAux.getClass());
investors_per_location=objectMapper.readValue(jsonData, mapType);
我最好的猜测是,这不是在 HashMap 中包含链接列表以从 JSON 文件加载它的方法。 有什么线索吗? 提前致谢,大卫。
最佳答案
尝试使用TypeReference
代替:
TypeReference<Map<String, LinkedList<Investor>>> typeRef = new TypeReference<Map<String, LinkedList<Investor>>>(){};
Map<String, LinkedList<Investor>> investorsPerLocation = objectMapper.readValue(jsonData, typeRef);
关于HashMap<String,LinkedList<Investor>> 的 java jackson 数据绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60030112/