[英]Jackson ObjectMapper: How to omit (ignore) null array element [null]
I have Json array containing null
value in array.我有 Json 数组,其中包含数组中的
null
值。
{
myArray: [ null ]
}
How to configure Jackson ObjectMapper to ignore such null
array elements - as if it was empty array []
?如何配置 Jackson ObjectMapper 以忽略此类
null
数组元素 - 就好像它是空数组[]
?
Constrains:约束:
You can use contentNulls
property from JsonSetter annotation.您可以使用JsonSetter注释中的
contentNulls
属性。 Your POJO
class could look like below:您的
POJO
class 可能如下所示:
class ArrayWrapper {
private List<String> myArray;
@JsonSetter(contentNulls = Nulls.SKIP)
public void setMyArray(List<String> myArray) {
this.myArray = myArray;
}
public List<String> getMyArray() {
return myArray;
}
}
See also:也可以看看:
Maybe @JsonIclude works?也许@JsonIclude 有效?
@JsonInclude(value=Include.NON_EMPTY, content=Include.NON_NULL)
http://fasterxml.github.io/jackson-annotations/javadoc/2.9/com/fasterxml/jackson/annotation/JsonInclude.html?is-external=true http://fasterxml.github.io/jackson-annotations/javadoc/2.9/com/fasterxml/jackson/annotation/JsonInclude.ZFC35FDC70D5FC69D7A368ZisA822
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.