杰克逊 - 如何解析这个领域?
Jackson - How to parse this field?
我有以下 JSON(来自网络服务):
{
"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"
}
}, (...)
而且我还有以下 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;
(...)
}
我不能只将 @JsonProperty
放入 latitude/longitude 变量中,因为这些值位于 JSON.
的 "locations" 部分内
如何在此处用 Jackson 注释纬度/经度字段?
您需要像这样在您的用户 class 中创建位置列表。
@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
(...)
}
我有以下 JSON(来自网络服务):
{
"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"
}
}, (...)
而且我还有以下 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;
(...)
}
我不能只将 @JsonProperty
放入 latitude/longitude 变量中,因为这些值位于 JSON.
如何在此处用 Jackson 注释纬度/经度字段?
您需要像这样在您的用户 class 中创建位置列表。
@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
(...)
}