【发布时间】:2021-12-06 11:13:50
【问题描述】:
我可以有这样的 JSON:
[
{
"number": 123,
"items" : [
{"product": "P1","cost":10.5},
{"product": "P2","cost":5.25}
],
"tags":["a","b","c"],
"customer": {
"name": "Roberto",
"shortName": "Beto"
},
"actions": [{
"moment": "2021-01-01 11:22:22.222",
"description": "action 1"
},{
"moment": "2021-01-23 11:22:22.222",
"description": "action 2"
}]
}
]
我需要使用joins 获得查询的 SQL 结果之类的输出。注意,输出必须根据复杂的关联进行协调(在上面的例子中,属性:项目和动作):
[
{ "number": 123, "items_product" : "P1", "items_cost": 10.5, "tags": null, "actions_moment": null, "actions_description": null}
{ "number": 123, "items_product" : "P2", "items_cost": 5.25, "tags": null, "actions_moment": null, "actions_description": null}
{ "number": 123, "items_product" : null, "items_cost": null, "tags": "a", "actions_moment": null, "actions_description": null}
{ "number": 123, "items_product" : null, "items_cost": null, "tags": "b", "actions_moment": null, "actions_description": null}
{ "number": 123, "items_product" : null, "items_cost": null, "tags": "c", "actions_moment": null, "actions_description": null}
{ "number": 123, "items_product" : null, "items_cost": null, "tags": null, "actions_moment": "2021-01-01 11:22:22.222", "actions_description": "Expedicao"}
{ "number": 123, "items_product" : null, "items_cost": null, "tags": null, "actions_moment": "2021-01-23 11:22:22.222", "actions_description": "Bla bla bla"}
]
我需要使用 Java 和 Google Gson 动态生成输出。
【问题讨论】:
-
这能回答你的问题吗? Transform and flatten JSON using GSON
-
这不是同一个问题,预期的结果不同。