HashMap<String,LinkedList<Investor>> 的 java jackson 数据绑定(bind)

标签 java json serialization data-binding jackson

我正在尝试加载从 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/

相关文章:

java - 通过 JNI 访问 C 中的缓存

java - jaspertreport v.6.1.1 : font extension not working for international language

php - JSON 只有一行在打印

json - 在 TypeScript 中导入 JSON 文件

java - 1.7序列化的HashMap,1.6能用吗?

java - JRootPane.getName() 返回 Null?

java - 一个很好的 java (tomcat) SOAP 库

javascript - Nodejs服务器没有收到来自POST请求的任何参数

C# BinaryFormatter - 如何找出二进制数据的类?

c# - 列表集合 XML 序列化