Top Description Inners Methods
com.fasterxml.jackson.databind.annotation

public @Interface JsonSerialize

extends Annotation
Annotations
@Target:ANNOTATION_TYPE, METHOD, FIELD, TYPE, PARAMETER
@Retention:RUNTIME
@JacksonAnnotation
Imports
java.lang.annotation.ElementType, .Retention, .RetentionPolicy, .Target, com.fasterxml.jackson.databind.*, com.fasterxml.jackson.databind.util.Converter

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)

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
JsonSerialize.Inclusion

Deprecated
Enumeration used with JsonSerialize#include property to define which properties of Java Beans are to be included in serialization
public static enum
JsonSerialize.Typing

Enumeration used with JsonSerialize#typing property to define whether type detection is based on dynamic runtime type (DYNAMIC) or declared type (STATIC).

Method Summary

Modifier and TypeMethod and Description
public Class<?>
as()

Supertype (of declared type, which itself is supertype of runtime type) to use as type when locating serializer to use.

public Class<?>
contentAs()

Concrete type to serialize content value (elements of a Collection/array, values of Maps) as, instead of type otherwise declared.

public Class<? extends Converter<IN, OUT>>
contentConverter()

Similar to converter, but used for values of structures types (List, arrays, Maps).

public Class<? extends JsonSerializer<T>>
contentUsing()

Serializer class to use for serializing contents (elements of a Collection/array, values of Maps) of annotated property.

public Class<? extends Converter<IN, OUT>>
converter()

Which helper object is to be used to convert type into something that Jackson knows how to serialize; either because base type cannot be serialized easily, or just to alter serialization.

public JsonSerialize.Inclusion
include()
Deprecated As of Jackson 2.0, this annotation has been replaced by com.fasterxml.jackson.annotation.JsonInclude

Which properties of annotated Bean are to be included in serialization (has no effect on other types like enums, primitives or collections).

public Class<?>
keyAs()

Concrete type to serialize keys of java.util.Map as, instead of type otherwise declared.

public Class<? extends JsonSerializer<T>>
keyUsing()

Serializer class to use for deserializing Map keys of annotated property or Map keys of value type so annotated.

public Class<? extends JsonSerializer<T>>
nullsUsing()

Serializer class to use for serializing nulls for properties that are annotated, instead of the default null serializer.

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

public Class<? extends JsonSerializer<T>>
using()

Serializer class to use for serializing associated value.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

asback to summary
public Class<?> as()

Supertype (of declared type, which itself is supertype of runtime type) to use as type when locating serializer to use.

Bogus type Void 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.

contentAsback to summary
public 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.

contentConverterback to summary
public Class<? extends Converter<IN, OUT>> contentConverter()

Similar to converter, but used for values of structures types (List, arrays, Maps). Note that this property does NOT have effect when used as Class annotation; it can only be used as property annotation: this because association between container and value types is loose and as such converters seldom make sense for such usage.

Annotations
@SuppressWarnings:rawtypes
Since
2.2
contentUsingback to summary
public Class<? extends JsonSerializer<T>> contentUsing()

Serializer class to use for serializing contents (elements of a Collection/array, values of Maps) of annotated property. Can only be used on accessors (methods, fields, constructors), to apply to values of java.util.Map-valued properties; not applicable for value types used as Array elements or java.util.Collection and java.util.Map values.

Annotations
@SuppressWarnings:rawtypes
converterback to summary
public Class<? extends Converter<IN, OUT>> converter()

Which helper object is to be used to convert type into something that Jackson knows how to serialize; either because base type cannot be serialized easily, or just to alter serialization.

Annotations
@SuppressWarnings:rawtypes
Since
2.2
includeback to summary
public JsonSerialize.Inclusion include()

Deprecated

As of Jackson 2.0, this annotation has been replaced by com.fasterxml.jackson.annotation.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).

This property has been replaced by special-purpose com.fasterxml.jackson.annotation.JsonInclude annotation, introduced in Jackson 2.0.

Note that Jackson 2.3 changed default to DEFAULT_INCLUSION, which is roughly same as saying "whatever". This is important because it allows hierarchic default values to be used.

Annotations
@Deprecated
keyAsback to summary
public Class<?> keyAs()

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.

keyUsingback to summary
public Class<? extends JsonSerializer<T>> keyUsing()

Serializer class to use for deserializing Map keys of annotated property or Map keys of value type so annotated. Can be used both on accessors (methods, fields, constructors), to apply to values of java.util.Map-valued properties, and on "key" classes, to apply to use of annotated type as java.util.Map keys (latter starting with Jackson 2.11).

Annotations
@SuppressWarnings:rawtypes
nullsUsingback to summary
public Class<? extends JsonSerializer<T>> nullsUsing()

Serializer class to use for serializing nulls for properties that are annotated, instead of the default null serializer. Note that using this property when annotation types (classes) has no effect currently (it is possible this could be improved in future).

Annotations
@SuppressWarnings:rawtypes
Since
2.3
typingback to summary
public 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).

Note that Jackson 2.3 changed default to DEFAULT_TYPING, which is roughly same as saying "whatever". This is important as it allows avoiding accidental overrides at property level.

usingback to summary
public Class<? extends JsonSerializer<T>> 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 the value of the property annotated.

Annotations
@SuppressWarnings:rawtypes
com.fasterxml.jackson.databind.annotation back to summary

public final Enum JsonSerialize.Inclusion

extends Enum<JsonSerialize.Inclusion>
Class Inheritance
Annotations
@Deprecated

Deprecated

Enumeration used with JsonSerialize#include property to define which properties of Java Beans are to be included in serialization

Field Summary

Modifier and TypeField and Description
public static final JsonSerialize.Inclusion
ALWAYS

References Deprecated JsonSerialize.Inclusion is deprecated or references (maybe indirectly) at least one deprecated element.
Value that indicates that properties are to be always included, independent of value
public static final JsonSerialize.Inclusion
DEFAULT_INCLUSION

References Deprecated JsonSerialize.Inclusion is deprecated or references (maybe indirectly) at least one deprecated element.
Pseudo-value that is used to indicate "use whatever is default used at higher level".
public static final JsonSerialize.Inclusion
NON_DEFAULT

References Deprecated JsonSerialize.Inclusion is deprecated or references (maybe indirectly) at least one deprecated element.
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.
public static final JsonSerialize.Inclusion
NON_EMPTY

References Deprecated JsonSerialize.Inclusion is deprecated or references (maybe indirectly) at least one deprecated element.
Value that indicates that only properties that have values that values that are null or what is considered empty are not to be included.
public static final JsonSerialize.Inclusion
NON_NULL

References Deprecated JsonSerialize.Inclusion is deprecated or references (maybe indirectly) at least one deprecated element.
Value that indicates that only properties with non-null values are to be included.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static JsonSerialize.Inclusion
valueOf(String name)
References Deprecated JsonSerialize.Inclusion is deprecated or references (maybe indirectly) at least one deprecated element.

public static JsonSerialize.Inclusion[]
values()
References Deprecated JsonSerialize.Inclusion is deprecated or references (maybe indirectly) at least one deprecated element.

Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ALWAYSback to summary
public static final JsonSerialize.Inclusion ALWAYS

References Deprecated

JsonSerialize.Inclusion is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Value that indicates that properties are to be always included, independent of value

DEFAULT_INCLUSIONback to summary
public static final JsonSerialize.Inclusion DEFAULT_INCLUSION

References Deprecated

JsonSerialize.Inclusion is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Pseudo-value that is used to indicate "use whatever is default used at higher level".

Since
2.3
NON_DEFAULTback to summary
public static final JsonSerialize.Inclusion NON_DEFAULT

References Deprecated

JsonSerialize.Inclusion is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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_EMPTYback to summary
public static final JsonSerialize.Inclusion NON_EMPTY

References Deprecated

JsonSerialize.Inclusion is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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 other types, non-null values are to be included.
NON_NULLback to summary
public static final JsonSerialize.Inclusion NON_NULL

References Deprecated

JsonSerialize.Inclusion is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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

Constructor Detail

Inclusionback to summary
private Inclusion()

Method Detail

valueOfback to summary
public static JsonSerialize.Inclusion valueOf(String name)

References Deprecated

JsonSerialize.Inclusion is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

valuesback to summary
public static JsonSerialize.Inclusion[] values()

References Deprecated

JsonSerialize.Inclusion is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

com.fasterxml.jackson.databind.annotation back to summary

public final Enum JsonSerialize.Typing

extends Enum<JsonSerialize.Typing>
Class Inheritance

Enumeration used with JsonSerialize#typing property to define whether type detection is based on dynamic runtime type (DYNAMIC) or declared type (STATIC).

Field Summary

Modifier and TypeField and Description
public static final JsonSerialize.Typing
DEFAULT_TYPING

Pseudo-value that is used to indicate "use whatever is default used at higher level".

public static final JsonSerialize.Typing
DYNAMIC

Value that indicates that the actual dynamic runtime type is to be used.

public static final JsonSerialize.Typing
STATIC

Value that indicates that the static declared type is to be used.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static JsonSerialize.Typing
public static JsonSerialize.Typing[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DEFAULT_TYPINGback to summary
public static final JsonSerialize.Typing DEFAULT_TYPING

Pseudo-value that is used to indicate "use whatever is default used at higher level".

Since
2.3
DYNAMICback to summary
public static final JsonSerialize.Typing DYNAMIC

Value that indicates that the actual dynamic runtime type is to be used.

STATICback to summary
public static final JsonSerialize.Typing STATIC

Value that indicates that the static declared type is to be used.

Constructor Detail

Typingback to summary
private Typing()

Method Detail

valueOfback to summary
public static JsonSerialize.Typing valueOf(String name)
valuesback to summary
public static JsonSerialize.Typing[] values()