Annotation Interface JsonInclude
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 JsonInclude.Include.NON_NULL
it is possible that JSON null values are output, if object reference
in question is not `null`. An example is AtomicReference
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 JsonInclude.Include.NON_EMPTY
for a Map
would
exclude Map
s with no values, but would include Map
s
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
Map
s that only contain
"empty" elements, or "non-default" values (see JsonInclude.Include.NON_EMPTY
and
JsonInclude.Include.NON_DEFAULT
for more details).
In addition to `Map`s, `content` concept is also supported for referential
types (like AtomicReference
).
Note that `content` is NOT currently (as of Jackson 2.9) supported for
arrays or Collection
s, but supported may be added in
future versions.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enumeration used withJsonInclude
to define which properties of Java Beans are to be included in serialization.static class
Helper class used to contain information from a singleJsonInclude
annotation. -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionInclusion rule to use for entries ("content") of annotatedMap
s and referential types (likeAtomicReference
); defaults toJsonInclude.Include.ALWAYS
.Class<?>
Specifies type of "Filter Object" to use in casecontent()
isJsonInclude.Include.CUSTOM
: if so, an instance is created by callingHandlerInstantiator
(ofObjectMapper
), which by default simply calls zero-argument constructor of the Filter Class.Inclusion rule to use for instances (values) of types (Classes) or properties annotated; defaults toJsonInclude.Include.ALWAYS
.Class<?>
Specifies type of "Filter Object" to use in casevalue()
isJsonInclude.Include.CUSTOM
: if so, an instance is created by callingHandlerInstantiator
(ofObjectMapper
), which by default simply calls zero-argument constructor of the Filter Class.
-
Element Details
-
value
JsonInclude.Include valueInclusion rule to use for instances (values) of types (Classes) or properties annotated; defaults toJsonInclude.Include.ALWAYS
.- Returns:
- Inclusion rule for value itself
- Default:
- USE_DEFAULTS
-
content
JsonInclude.Include contentInclusion rule to use for entries ("content") of annotatedMap
s and referential types (likeAtomicReference
); defaults toJsonInclude.Include.ALWAYS
.- Returns:
- Inclusion rule for content (elements, values of structured types)
- Default:
- USE_DEFAULTS
-
valueFilter
Class<?> valueFilterSpecifies type of "Filter Object" to use in casevalue()
isJsonInclude.Include.CUSTOM
: if so, an instance is created by callingHandlerInstantiator
(ofObjectMapper
), which by default simply calls zero-argument constructor of the Filter Class.Whether the value is to be included or not is determined by calling Filter's
equals(value)
method: if it returnstrue
value is NOT included (it is "filtered out"); iffalse
value IS included ("not filtered out").- Default:
- java.lang.Void.class
-
contentFilter
Class<?> contentFilterSpecifies type of "Filter Object" to use in casecontent()
isJsonInclude.Include.CUSTOM
: if so, an instance is created by callingHandlerInstantiator
(ofObjectMapper
), which by default simply calls zero-argument constructor of the Filter Class.Whether the content value is to be included or not is determined by calling Filter's
equals(value)
method: if it returnstrue
content value is NOT included (it is "filtered out"); iffalse
content value IS included ("not filtered out").- Default:
- java.lang.Void.class
-