Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.annotation;
  
  
Annotation used for configuring serialization aspects, by attaching to "getter" methods or fields, or to value classes. When annotating value classes, configuration is used for instances of the value class but can be overridden by more specific annotations (ones that attach to methods or fields).

An example annotation would be:

  @JsonSerialize(using=MySerializer.class,
    as=MySubClass.class,
    typing=JsonSerialize.Typing.STATIC
  )
(which would be redundant, since some properties block others: specifically, 'using' has precedence over 'as', which has precedence over 'typing' setting)
 
 public @interface JsonSerialize
 {
     // // // Annotations for explicitly specifying deserializer
 
    
Serializer class to use for serializing associated value. Depending on what is annotated, value is either an instance of annotated class (used globablly anywhere where class serializer is needed); or only used for serializing property access via a getter method.
 
     public Class<? extends JsonSerializer<?>> using() default JsonSerializer.None.class;

    
Serializer class to use for serializing contents (elements of a Collection/array, values of Maps) of annotated property. Can only be used on properties (methods, fields, constructors), and not value classes themselves (as they are typically generic)
 
     public Class<? extends JsonSerializer<?>> contentUsing()
         default JsonSerializer.None.class;

    
Serializer class to use for serializing Map keys of annotated property. Can only be used on properties (methods, fields, constructors), and not value classes themselves.
 
     public Class<? extends JsonSerializer<?>> keyUsing()
         default JsonSerializer.None.class;
     
     // // // Annotations for type handling, explicit declaration
     // // // (type used for choosing deserializer, if not explicitly
     // // // specified)
 
    
Supertype (of declared type, which itself is supertype of runtime type) to use as type when locating serializer to use.

Bogus type NoClass can be used to indicate that declared type is used as is (i.e. this annotation property has no setting); this since annotation properties are not allowed to have null value.

Note: if using is also used it has precedence (since it directly specifies serializer, whereas this would only be used to locate the serializer) and value of this annotation property is ignored.

 
     public Class<?> as() default NoClass.class;

    
Concrete type to serialize keys of java.util.Map as, instead of type otherwise declared. Must be a supertype of declared type; otherwise an exception may be thrown by serializer.
 
     public Class<?> keyAs() default NoClass.class;

    
Concrete type to serialize content value (elements of a Collection/array, values of Maps) as, instead of type otherwise declared. Must be a supertype of declared type; otherwise an exception may be thrown by serializer.
 
     public Class<?> contentAs() default NoClass.class;
    
    
Whether type detection used is dynamic or static: that is, whether actual runtime type is used (dynamic), or just the declared type (static).
    public Typing typing() default .;
    // // // Annotation(s) for inclusion criteria

    
Which properties of annotated Bean are to be included in serialization (has no effect on other types like enums, primitives or collections). Choices are "all", "properties that have value other than null" and "properties that have non-default value" (i.e. default value being property setting for a Bean constructed with default no-arg constructor, often null).

Deprecated:
As of Jackson 2.0, this annotation has been replaced by com.fasterxml.jackson.annotation.JsonInclude
    @Deprecated
    public Inclusion include() default .;
    
    /*
    /**********************************************************
    /* Value enumerations needed
    /**********************************************************
     */

    
Enumeration used with JsonSerialize.include() property to define which properties of Java Beans are to be included in serialization
    public enum Inclusion
    {
        
Value that indicates that properties are to be always included, independent of value
        ALWAYS,

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

        
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.
        NON_DEFAULT,

        
Value that indicates that only properties that have values that values that are null or what is considered empty are not to be included. 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
    • For other types, non-null values are to be included.
        NON_EMPTY
        ;
    }

    
Enumeration used with JsonSerialize.typing() property to define whether type detection is based on dynamic runtime type (DYNAMIC) or declared type (STATIC).
    public enum Typing
    {
        
Value that indicates that the actual dynamic runtime type is to be used.
        DYNAMIC,

        
Value that indicates that the static declared type is to be used.
        STATIC
        ;
    }
New to GrepCode? Check out our FAQ X