|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||
@Target(value={ANNOTATION_TYPE,METHOD,FIELD,TYPE,PARAMETER})
@Retention(value=RUNTIME)
public @interface JsonIncludeAnnotation used to indicate when value of the annotated property (when used for a field, method or constructor parameter), or all properties of the annotated class, is to be serialized. Without annotation property values are always included, but by using this annotation one can specify simple exclusion rules to reduce amount of properties to write out.
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 {link java.util.List} would
exclude Lists with no Java elements, but would include Lists
with `null` elements. To exclude Lists with only nulls, you would use both
annotations like so:
public class Bean {
| Optional Element Summary | |
|---|---|
JsonInclude.Include |
content
Inclusion rule to use for entries ("content") of annotated Maps; defaults to JsonInclude.Include.ALWAYS. |
JsonInclude.Include |
value
Inclusion rule to use for instances (values) of types (Classes) or properties annotated. |
public abstract JsonInclude.Include value
public abstract JsonInclude.Include content
Maps; defaults to JsonInclude.Include.ALWAYS.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||