gpt4 book ai didi

java - Jackson - 如何解析这个字段?

转载 作者:太空宇宙 更新时间:2023-11-04 13:27:48 24 4
gpt4 key购买 nike

我有以下 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"
}
}, (...)

我还有以下 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 放入纬度/经度变量中,因为这些值位于 JSON 的“位置”部分内。

如何在此处使用 Jackson 注释纬度/经度字段?

最佳答案

您需要像这样在 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
(...)
}

关于java - Jackson - 如何解析这个字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32493050/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com