[英]How to exclude a Null List in a JSON object while Parsing to POJO
I have A JSON Response which is having some Object and Objects have some List of values.我有一个 JSON 响应,它有一些 Object 和对象有一些值列表。
"A": {
"Object1": {
"list":[
null,
null,
null
]
}
"Object2": {
"list":[
null,
null,
null
]
}
"Object3": {
"list":[
2,
3,
8
]
}
}
I want to exclude the Complete Object "Object1" and "Object2" if the list is having null values.如果列表具有 null 值,我想排除完整的 Object“Object1”和“Object2”。
I tried我试过了
@JsonInclude(Include.NON_NULL)
both at class level and field level but still its not excluding.在 class 级别和现场级别,但仍然不排除。
You can use @JsonSetter
annotation on the field with specification, how nulls should be handled:您可以在具有规范的字段上使用@JsonSetter
注释,应如何处理空值:
@JsonSetter(nulls=Nulls.AS_EMPTY) // null will clear to empty list
public List<String> names = Collections.emptyList();
(you need at Jackson in version at least 2.9) (您需要至少 2.9 版的 Jackson)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.