Annotation Type 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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enumeration used withinclude()
property to define which properties of Java Beans are to be included in serializationstatic enum
Enumeration used withtyping()
property to define whether type detection is based on dynamic runtime type (DYNAMIC) or declared type (STATIC). -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionClass
<?> Supertype (of declared type, which itself is supertype of runtime type) to use as type when locating serializer to use.Class
<?> Concrete type to serialize content value (elements of a Collection/array, values of Maps) as, instead of type otherwise declared.Class
<? extends JsonSerializer<?>> Serializer class to use for serializing contents (elements of a Collection/array, values of Maps) of annotated property.Which properties of annotated Bean are to be included in serialization (has no effect on other types like enums, primitives or collections).Class
<?> Concrete type to serialize keys ofMap
as, instead of type otherwise declared.Class
<? extends JsonSerializer<?>> Serializer class to use for serializing Map keys of annotated property.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<?>> Serializer class to use for serializing associated value.
-
Element Details
-
using
Class<? extends JsonSerializer<?>> usingSerializer 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
-
contentUsing
Class<? extends JsonSerializer<?>> contentUsingSerializer 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)- Since:
- 1.8
- Default:
org.codehaus.jackson.map.JsonSerializer.None.class
-
keyUsing
Class<? extends JsonSerializer<?>> keyUsingSerializer class to use for serializing Map keys of annotated property. Can only be used on properties (methods, fields, constructors), and not value classes themselves.- Since:
- 1.8
- Default:
org.codehaus.jackson.map.JsonSerializer.None.class
-
as
Class<?> asSupertype (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:
org.codehaus.jackson.map.annotate.NoClass.class
-
keyAs
Class<?> keyAsConcrete type to serialize keys ofMap
as, instead of type otherwise declared. Must be a supertype of declared type; otherwise an exception may be thrown by serializer.- Default:
org.codehaus.jackson.map.annotate.NoClass.class
-
contentAs
Class<?> contentAsConcrete 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:
org.codehaus.jackson.map.annotate.NoClass.class
-
typing
JsonSerialize.Typing typingWhether 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:
DYNAMIC
-
include
JsonSerialize.Inclusion includeWhich 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:
ALWAYS
-