Top Description Inners Methods
tools.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, tools.jackson.databind.*, tools.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.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 ValueSerializer<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 Class<?>
keyAs()

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

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

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

public Class<? extends ValueSerializer<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 ValueSerializer<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
contentUsingback to summary
public Class<? extends ValueSerializer<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
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 ValueSerializer<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 ValueSerializer<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
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 ValueSerializer<T>> using()

Serializer class to use for serializing associated value. Depending on what is annotated, value is either an instance of annotated class (used globally anywhere where class serializer is needed); or only used for serializing the value of the property annotated.

Annotations
@SuppressWarnings:rawtypes
tools.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".

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