我有一个List<Map<String, Object>>
这样的列表
[{"A": 2616100,
"B": 2616100,
"C": 31,
"D": "Sold Promissory Buyer"
},
{
"A": 101322143.24,
"B": 50243301.2,
"C": 569,
"D": "Auction"
},
{
"A": 72000,
"B": 93900,
"C": 1,
"D": "Sold Third Party"
}]
使用带有 groupBy 方法的 Stream API salesReportForSoldProperty.stream().collect(Collectors.groupingBy(tags -> tags.get("D")))
,我可以获得集合Map<Object, List<Map<String, Object>>>
但是当我尝试创建这个集合的 JSON 时,我得到这样的 Json
{
"Sold Promissory Buyer": [
{
"A": 2616100,
"B": 2616100,
"C": 31,
"D": "Sold Promissory Buyer"
}
],
"Auction": [
{
"A": 101322143.24,
"B": 50243301.2,
"C": 569,
"D": "Auction"
}
],
"Sold Third Party": [
{
"A": 72000,
"B": 93900,
"C": 1,
"D": "Sold Third Party"
}
]
}
这里每个值都是 JSONArray,因为我得到Map<Object, List<Map<String, Object>>>
. 有没有办法Map<Object, Map<String, Object>>
使用 Stream API 来收集,所以我可以得到一个正确的 JSON(没有 JSONArray 值)