org.codehaus.jackson.map.annotate
Annotation Type JsonSerialize


@Target(value={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,
    include=JsonSerialize.Inclusion.NON_NULL,
    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)

NOTE: since version 1.2, annotation has also been applicable to (constructor) parameters

Since:
1.1

Optional Element Summary
 Class<?> as
          Subtype (of declared type, which itself is subtype of runtime type) to use as type when locating serializer to use.
 JsonSerialize.Inclusion include
          Which properties of annotated Bean are to be included in serialization (has no effect on other types like enums, primitives or collections).
 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:
org.codehaus.jackson.map.JsonSerializer.None.class

as

public abstract Class<?> as
Subtype (of declared type, which itself is subtype 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 specified serializer, whereas this would only be used to locate the serializer) and value of this annotation property is ignored.

Default:
org.codehaus.jackson.map.annotate.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).

Since:
1.2
Default:
org.codehaus.jackson.map.annotate.JsonSerialize.Typing.DYNAMIC

include

public abstract JsonSerialize.Inclusion include
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:
org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.ALWAYS