当前位置: 首页 > 知识库问答 >
问题:

HashMap的java jackson数据绑定

巢靖
2023-03-14

我试图加载从JSON文件中获取的值。-重新加载JSON文件的目标对象是:

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文件加载回来的方法。有线索吗?谢谢你,大卫。


共有1个答案

施琦
2023-03-14

尝试使用类型参考代替:

TypeReference<Map<String, LinkedList<Investor>>> typeRef = new TypeReference<Map<String, LinkedList<Investor>>>(){};
Map<String, LinkedList<Investor>> investorsPerLocation = objectMapper.readValue(jsonData, typeRef);
 类似资料:
  • 数据绑定 JXML 中的动态数据来自于该 Page 的 data字段。 简单绑定 数据绑定使用 Mustache 语法(双大括号)将变量包起来,可以作用于以下: 页面内容 <view> hello {{ name }} </view> Page({ data: { name: 'cortana' } }) 组件属性(需要在双引号之内) <view id="{{id}}"> </

  • 我想在JavaFX中显示内容。下面是我用来将内容设置到表列中的代码。我遇到的问题是,它只显示一行。循环只迭代了5次:每次它都会获取的第一个值。 如果忽略行,则循环将迭代中的所有内容。

  • attr绑定是用来为html元素绑定属性值的,这种绑定非常有用,例如我们需要想一个元素添加title属性,或者为img标签添加src属性。 示例代码: //.W片段 <a bind-attr="{ href: url, title: details }"> Report </a> //js片段 this.url=justep.Bind.observable("year-end.html"),

  • submit绑定只能用在form元素中,当form提交的时候被触发,并且默认阻止form的提交。因此我们通常在submit的处理函数中以ajax的方式提交form表单。 示例代码: //.W片段 <form bind-submit="doSomething"> ... form contents go here ... <button type="submit">Submit</butt

  • with绑定用来创建一个绑定上下文,在子元素内的所有绑定都在这个上下文中进行。 示例代码: //.W片段 <h1 bind-text="city"> </h1> <p bind-with="coords"> Latitude: <span bind-text="latitude"> </span>, Longitude: <span bind-text="longitude"> </span

  • foreach绑定用来处理数组,通常用来将一个数组绑定到一个列表或者table中。在foreach绑定中,我们可以使用if、with等嵌套绑定。 示例代码: //.W片段 <table> <thead> <tr><th>First name</th><th>Last name</th></tr> </thead> <tbody bind-foreach="people"> <tr>