【发布时间】:2022-01-31 03:15:27
【问题描述】:
我有以下课程:
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class User {
private String id;
private List<Reference> references;
.....
}
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Reference {
@JacksonXmlProperty(isAttribute = true)
private String ref;
public Reference(final String ref) {
this.ref = ref;
}
public Reference() { }
public String getRef() {
return ref;
}
}
当序列化为 XML 时,格式符合预期,但当我尝试序列化为 JSON 时,我得到以下信息
"users" : [
{
"references" : [
{
"ref": "referenceID"
}
]
}
]
我需要它是:
"users" : [
{
"references" : [
"referenceID"
]
}
]
包含引用列表的大括号我需要在没有属性名称的情况下忽略它
【问题讨论】:
标签: java json jackson jsonparser