【发布时间】:2018-10-01 20:52:29
【问题描述】:
执行查询后,结果将转换为 JSON。格式如下:
[
{
"version": "1.0.1",
"device.id": 1234,
"user.id": 1234,
"device.platform": "IOS",
"lastActivity": null,
"id": 987,
"when": "2017-08-05",
"device.platformVersion": "1.2.2",
"endPointArn": "arn-here-123"
},
{
"version": "1.0.2",
"device.id": 2345,
"user.id": 9876,
"device.platform": "IOS",
"lastActivity": null,
"id": 753,
"when": "2017-08-05",
"device.platformVersion": "1.2.2",
"endPointArn": "arn-here-123"
}
]
我需要为 List 对象映射此 json,其中:
public class DeviceUser {
private Integer id;
private String version;
private Date when;
private String endPointArn;
private Device device;
private User user;
}
我们可以看到带有 attrObject.fieldObject 的键(例如:“device.id”:2345),我看不到转换为预期格式的方法。 指定的最终格式是:
[
{
"version": "1.0.1",
"user": {
"id": 1234
},
"device": {
"id": 1234,
"platform": "IOS",
"platformVersion": "1.2.2"
},
"lastActivity": null,
"id": 987,
"when": "2017-08-05",
"endPointArn": "arn-here-123"
},
{
"user": {
"id": 9876
},
"device": {
"id": 2345,
"platform": "IOS",
"platformVersion": "1.2.2"
},
"version": "1.0.2",
"lastActivity": null,
"id": 753,
"when": "2017-08-05",
"endPointArn": "arn-here-123"
}
]
【问题讨论】:
-
使用新的 json,你必须创建嵌套对象,或者使用 json-path