Note that the main inclusion criteria (one annotated with value)
is checked on Java object level, for the annotated type,
and NOT on JSON output -- so even with Include#NON_NULL
it is possible that JSON null values are output, if object reference
in question is not `null`. An example is java.
instance constructed to reference null value: such a value
would be serialized as JSON null, and not filtered out.
To base inclusion on value of contained value(s), you will typically also need
to specify content() annotation; for example, specifying only
value as Include#NON_EMPTY for a java. would
exclude Maps with no values, but would include Maps
with `null` values. To exclude Map with only `null` value, you would use both
annotations like so:
public class Bean {
@JsonInclude(value=Include.NON_EMPTY, content=Include.NON_NULL)
public Map<String,String> entries;
}
Similarly you could exclude Maps that only contain
"empty" elements, or "non-default" values (see Include#NON_EMPTY and
Include#NON_DEFAULT for more details).
In addition to `Map`s, `content` concept is also supported for referential
types (like java.).
Note that `content` is NOT currently (as of Jackson 2.9) supported for
arrays or java.s, but supported may be added in
future versions.
| Modifier and Type | Class and Description |
|---|---|
| public static enum | JsonInclude.
Enumeration used with |
| public static class | JsonInclude.
Helper class used to contain information from a single |
| Modifier and Type | Method and Description |
|---|---|
| public JsonInclude. | Returns: Inclusion rule for content (elements, values of structured types)Inclusion rule to use for entries ("content") of annotated
|
| public Class | contentFilter()
Specifies type of "Filter Object" to use in case
|
| public JsonInclude. | Returns: Inclusion rule for value itselfInclusion rule to use for instances (values) of types (Classes) or
properties annotated; defaults to |
| public Class | valueFilter()
Specifies type of "Filter Object" to use in case
|
| content | back to summary |
|---|---|
| public JsonInclude. Inclusion rule to use for entries ("content") of annotated
| |
| contentFilter | back to summary |
|---|---|
| public Class Specifies type of "Filter Object" to use in case
Whether the content value is to be included or not is determined by calling
Filter's
| |
| value | back to summary |
|---|---|
| public JsonInclude. Inclusion rule to use for instances (values) of types (Classes) or
properties annotated; defaults to
| |
| valueFilter | back to summary |
|---|---|
| public Class Specifies type of "Filter Object" to use in case
Whether the value is to be included or not is determined by calling
Filter's
| |
JsonInclude
to define which properties
of Java Beans are to be included in serialization.
| Modifier and Type | Field and Description |
|---|---|
| public static final JsonInclude. | ALWAYS
Value that indicates that property is to be always included, independent of value of the property. |
| public static final JsonInclude. | CUSTOM
Value that indicates that separate |
| public static final JsonInclude. | NON_ABSENT
Value that indicates that properties are included unless their value is:
|
| public static final JsonInclude. | NON_DEFAULT
Meaning of this setting depends on context: whether annotation is specified for POJO type (class), or not. |
| public static final JsonInclude. | NON_EMPTY
Value that indicates that only properties with null value, or what is considered empty, are not to be included. |
| public static final JsonInclude. | NON_NULL
Value that indicates that only properties with non-null values are to be included. |
| public static final JsonInclude. | USE_DEFAULTS
Pseudo-value used to indicate that the higher-level defaults make sense, to avoid overriding inclusion value. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static JsonInclude. | |
| public static JsonInclude. |
| ALWAYS | back to summary |
|---|---|
| public static final JsonInclude. Value that indicates that property is to be always included, independent of value of the property. | |
| CUSTOM | back to summary |
|---|---|
| public static final JsonInclude. Value that indicates that separate Note the filter will be called for each non-
| |
| NON_ABSENT | back to summary |
|---|---|
| public static final JsonInclude. Value that indicates that properties are included unless their value is:
| |
| NON_DEFAULT | back to summary |
|---|---|
| public static final JsonInclude. Meaning of this setting depends on context: whether annotation is specified for POJO type (class), or not. In latter case annotation is either used as the global default, or as property override.
When used for a POJO, definition is that only values that differ from
the default values of POJO properties are included. This is done
by creating an instance of POJO using zero-argument constructor,
and accessing property values: value is used as the default value
by using When NOT used for a POJO (that is, as a global default, or as property override), definition is such that:
| |
| NON_EMPTY | back to summary |
|---|---|
| public static final JsonInclude. Value that indicates that only properties with null value, or what is considered empty, are not to be included. Definition of emptiness is data type specific; see below for details on actual handling. Default emptiness for all types includes:
NON_NULL and NON_ABSENT.
Beyond this base, following types have additional empty values:
Note that this default handling can be overridden by custom
Compatibility note: Jackson 2.6 included a wider range of "empty" values than either earlier (up to 2.5) or later (2.7 and beyond) types; specifically:
NON_DEFAULT.
| |
| NON_NULL | back to summary |
|---|---|
| public static final JsonInclude. Value that indicates that only properties with non-null values are to be included. | |
| USE_DEFAULTS | back to summary |
|---|---|
| public static final JsonInclude. Pseudo-value used to indicate that the higher-level defaults make sense, to avoid overriding inclusion value. For example, if returned for a property this would use defaults for the class that contains property, if any defined; and if none defined for that, then global serialization inclusion details.
| |
| Include | back to summary |
|---|---|
| private Include() | |
| valueOf | back to summary |
|---|---|
| public static JsonInclude. | |
| values | back to summary |
|---|---|
| public static JsonInclude. | |
JsonInclude
annotation.
| Modifier and Type | Field and Description |
|---|---|
| protected final Class | |
| protected final JsonInclude. | |
| protected final Class | |
| protected final JsonInclude. | |
| protected static final JsonInclude. | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public | |
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public static JsonInclude. | construct(JsonInclude.
Factory method to use for constructing an instance for components |
| public static JsonInclude. | construct(JsonInclude.
Factory method to use for constructing an instance for components |
| public static JsonInclude. | |
| public boolean | equals(Object
the reference object with which to compare. o)Overrides java. Indicates whether some other object is "equal to" this one. |
| public static JsonInclude. | from(JsonInclude src)
Factory method to use for constructing an instance from instance of
|
| public Class | |
| public JsonInclude. | |
| public Class | |
| public JsonInclude. | |
| public int | |
| public static JsonInclude. | merge(JsonInclude.
Helper method that will try to combine values from two |
| public static JsonInclude. | |
| protected Object | |
| public String | |
| public Class | valueFor()
Implements com. Introspection method that may be used to find actual annotation that may be used as the source for value instance. |
| public JsonInclude. | withContentFilter(Class<?> filter)
Mutant factory that will either
|
| public JsonInclude. | |
| public JsonInclude. | withOverrides(JsonInclude.
Mutant factory method that merges values of this value with given override values, so that any explicitly defined inclusion in overrides has precedence over settings of this value instance. |
| public JsonInclude. | withValueFilter(Class<?> filter)
Mutant factory that will either
|
| public JsonInclude. |
| _contentFilter | back to summary |
|---|---|
protected final Class<?> _contentFilter
| |
| _contentInclusion | back to summary |
|---|---|
| protected final JsonInclude. | |
| _valueFilter | back to summary |
|---|---|
protected final Class<?> _valueFilter
| |
| _valueInclusion | back to summary |
|---|---|
| protected final JsonInclude. | |
| EMPTY | back to summary |
|---|---|
| protected static final JsonInclude. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| Value | back to summary |
|---|---|
| public Value(JsonInclude src) | |
| Value | back to summary |
|---|---|
| protected Value(JsonInclude. | |
| construct | back to summary |
|---|---|
| public static JsonInclude. Factory method to use for constructing an instance for components | |
| construct | back to summary |
|---|---|
| public static JsonInclude. Factory method to use for constructing an instance for components
| |
| empty | back to summary |
|---|---|
| public static JsonInclude. | |
| equals | back to summary |
|---|---|
| public boolean equals(Object o) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| from | back to summary |
|---|---|
| public static JsonInclude. Factory method to use for constructing an instance from instance of
| |
| getContentFilter | back to summary |
|---|---|
| public Class | |
| getContentInclusion | back to summary |
|---|---|
| public JsonInclude. | |
| getValueFilter | back to summary |
|---|---|
| public Class | |
| getValueInclusion | back to summary |
|---|---|
| public JsonInclude. | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| merge | back to summary |
|---|---|
| public static JsonInclude. Helper method that will try to combine values from two
| |
| mergeAll | back to summary |
|---|---|
public static JsonInclude.
| |
| readResolve | back to summary |
|---|---|
| protected Object readResolve() | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| valueFor | back to summary |
|---|---|
| public Class Implements com. Doc from com. Introspection method that may be used to find actual annotation that may be used as the source for value instance.
| |
| withContentFilter | back to summary |
|---|---|
| public JsonInclude. Mutant factory that will either
| |
| withContentInclusion | back to summary |
|---|---|
| public JsonInclude. | |
| withOverrides | back to summary |
|---|---|
| public JsonInclude. Mutant factory method that merges values of this value with given override
values, so that any explicitly defined inclusion in overrides has precedence over
settings of this value instance. If no overrides exist will return | |
| withValueFilter | back to summary |
|---|---|
| public JsonInclude. Mutant factory that will either
| |
| withValueInclusion | back to summary |
|---|---|
| public JsonInclude. | |