【发布时间】:2014-02-12 22:39:45
【问题描述】:
我正在尝试使用 Jersey 和 Jackson(尽管任何其他进行 JSON 解组的方式都可以)以某种形式(无论是 POJO 还是其他表示形式)将其输入我的系统。
基本上我只需要数据部分。我试图将 GenericTypes 与列表一起使用,但这是一个嵌套列表,我只是不确定该怎么做。非常感谢您的帮助,我真的很感激!
{
"total": 4,
"data": [
{
"descriptor": "",
"multiInstance": false,
"active": false
},
{
"descriptor": "Apparel",
"multiInstance": true,
},
{
"descriptor": "abcd123",
"multiInstance": false,
},
{
"descriptor": "abcd",
"multiInstance": false,
}
]
}
这是我正在尝试使用的类。我需要一个班级列表。
public class customObject {
@JsonProperty(value = "descriptor")
private String descriptor;
@JsonProperty(value = "multiInstance")
private Boolean multiInstance;
//getters and setters
}
编辑:
我在这里使用它。
CustomObjectResponse WDCOResponse = 资源 .type(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .header("授权", getToken()).get(WDCOResponse.class);
但是还是不行。
编辑2: 想通了!谢谢大家。 :)
我必须添加注释来告诉它在没有找到某些东西时忽略,我返回的一些 JSON 没有完全形成,因为并非所有字段都是绝对必要的。
【问题讨论】:
-
您是否尝试过使用jsonschema2pojo.org?