com.fasterxml.jackson.databind.annotation
Annotation Type JsonSerialize


@Target(value={ANNOTATION_TYPE,METHOD,FIELD,TYPE,PARAMETER})
@Retention(value=RUNTIME)
public @interface JsonSerialize

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)


Optional Element Summary
 Class<?> as
          Supertype (of declared type, which itself is supertype of runtime type) to use as type when locating serializer to use.
 Class<?> contentAs
          Concrete type to serialize content value (elements of a Collection/array, values of Maps) as, instead of type otherwise declared.
 Class<? extends JsonSerializer<?>> contentUsing
          Serializer class to use for serializing contents (elements of a Collection/array, values of Maps) of annotated property.
 JsonSerialize.Inclusion include
          Deprecated. As of Jackson 2.0, this annotation has been replaced by JsonInclude
 Class<?> keyAs
          Concrete type to serialize keys of Map as, instead of type otherwise declared.
 Class<? extends JsonSerializer<?>> keyUsing
          Serializer class to use for serializing Map keys of annotated property.
 JsonSerialize.Typing typing
          Whether type detection used is dynamic or static: that is, whether actual runtime type is used (dynamic), or just the declared type (static).
 Class<? extends JsonSerializer<?>> using
          Serializer class to use for serializing associated value.
 

using

public abstract Class<? extends JsonSerializer<?>> using
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.

Default:
com.fasterxml.jackson.databind.JsonSerializer.None.class

contentUsing

public abstract Class<? extends JsonSerializer<?>> contentUsing
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)

Default:
com.fasterxml.jackson.databind.JsonSerializer.None.class

keyUsing

public abstract Class<? extends JsonSerializer<?>> keyUsing
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.

Default:
com.fasterxml.jackson.databind.JsonSerializer.None.class

as

public abstract Class<?> as
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.

Default:
com.fasterxml.jackson.databind.annotation.NoClass.class

keyAs

public abstract Class<?> keyAs
Concrete type to serialize keys of Map as, instead of type otherwise declared. Must be a supertype of declared type; otherwise an exception may be thrown by serializer.

Default:
com.fasterxml.jackson.databind.annotation.NoClass.class

contentAs

public abstract Class<?> contentAs
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.

Default:
com.fasterxml.jackson.databind.annotation.NoClass.class

typing

public abstract JsonSerialize.Typing typing
Whether type detection used is dynamic or static: that is, whether actual runtime type is used (dynamic), or just the declared type (static).

Default:
com.fasterxml.jackson.databind.annotation.JsonSerialize.Typing.DYNAMIC

include

@Deprecated
public abstract JsonSerialize.Inclusion include
Deprecated. As of Jackson 2.0, this annotation has been replaced by JsonInclude

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).

Default:
com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion.ALWAYS


Copyright © 2012 fasterxml.com. All Rights Reserved.