【发布时间】:2019-07-15 05:15:34
【问题描述】:
我有一个像下面这样的 json
{
"department": [
{
"status": "active",
"count": "100"
},
{
"status": "active",
"count": "300"
}
],
"finance": [
{
"status": "inactive",
"count": "500"
},
{
"status": "active",
"count": "450"
}
]
}
我的对象如下所示
class CurrentInfo
{
private String status;
private int count;
//getters and setters
}
我想将此 JSON 转换为 Map<String,List<CurrentInfo>>。我可以使用以下方法转换单个节点
ObjectMapper mapper = new ObjectMapper();
CurrentInfo currentinfo = mapper.readValue(jsonString, CurrentInfo.class);
有没有办法可以将前面提到的JSON直接转换成Map<String,List<CurrentInfo>>
【问题讨论】:
-
你的地图的
key是什么?department、finance和 .. ? -
@user404 是的。你是对的
标签: java json jakarta-ee jackson objectmapper