[英]Jackson - How to parse this field?
I have the following JSON (coming from a WebService): 我有以下JSON(来自WebService):
{
"result": "success",
"users": [{
"id": 12345,
"login": "blabla",
"firstName": "first name here",
"lastName": "last name here",
"companyName": "company here",
"email": "email_here@test.com",
"phone": "",
"mobile": "123456789",
"locations": [{
"id": 123123,
"latitude": 23.330196,
"longitude": -92.026073,
"timestamp": "2015-08-17T01:43:21+00:00"
}],
"status": {
"message": "Message here",
"timestamp": "2015-07-31T01:50:51+00:00"
}
}, (...)
and I also have the following bean: 而且我还有以下bean:
@JsonTypeName("user")
public class User implements IdentityInterface
{
private long id;
@JsonProperty
private String firstName;
(...)
//How can I anotate this field?
private double latitude;
//How can I anotate this field?
private double longitude;
(...)
}
I can't just put @JsonProperty
in the latitude/longitude variables because those values are inside the "locations" part of the JSON. 我不能只将@JsonProperty
放入纬度/经度变量中,因为这些值位于JSON的“位置”部分内。
How can I annotate the latitude / longitude fields with Jackson here? 如何在此处使用Jackson注释纬度/经度字段?
You need to create a List of locations in your User class like so. 您需要像这样在User类中创建位置列表。
@JsonTypeName("user")
public class User implements IdentityInterface
{
private long id;
@JsonProperty
private String firstName;
(...)
@JsonProperty
private List<Location> locations;
}
public class Location{
private Long id;
private Double latitude;
private Double longitude;
private Date timestamp;
// Getters and setter
(...)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.