Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.jackson.annotation;
Annotation 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.

public @interface JsonInclude
Inclusion rule to use.
    public Include value() default .;
    /* Value enumerations needed

Enumeration used with JsonInclude to define which properties of Java Beans are to be included in serialization.

Note: Jackson 1.x had similarly named ("Inclusion") enumeration included in JsonSerialize annotation: it is not deprecated and this value used instead.

    public enum Include
Value that indicates that property is to be always included, independent of value of the property.

Value that indicates that only properties with non-null values are to be included.

Value that indicates that only properties that have values that differ from default settings (meaning values they have when Bean is constructed with its no-arguments constructor) are to be included. Value is generally not useful with java.util.Maps, since they have no default values; and if used, works same as ALWAYS.

Value that indicates that only properties that have values that values that are null or what is considered empty are not to be included.

Default emptiness is defined for following type:

  • For java.util.Collections and java.util.Maps, method isEmpty() is called;
  • For Java arrays, empty arrays are ones with length of 0
  • For Java java.lang.Strings, length() is called, and return value of 0 indicates empty String (note that String.isEmpty() was added in Java 1.6 and as such can not be used by Jackson
    • and for other types, non-null values are to be included.

      Note that this default handling can be overridden by custom JsonSerializer implementation: if method isEmpty() is overridden, it will be called to see if non-null values are considered empty (null is always considered empty).

New to GrepCode? Check out our FAQ X