[英]deserialise the list of integer from json to java using Jackson Object Mapper
[英]How to mapper a tree json object using jackson to List<>
执行查询后,结果将转换为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"
}
]
我需要将这个json映射为List <>对象,其中:
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"
}
]
如果使用的是Jackson,请尝试使用JsonPropety
注释对字段(或getter / setter)进行注释。
像这样:
@JsonProperty("device.id") private Device device;
因此,我使用结果集上的新转换器解决了这种情况。 转换器实际上只是迭代结果并搜索“。”。 使用反射。 我认为这是一个糟糕的策略。 因此,我接受新的答案。
我使用的转换器是: AliasToBeanNestedResultTransformer
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.