org.codehaus.jackson.annotate
Annotation Type JsonTypeInfo


@Target(value=TYPE)
@Retention(value=RUNTIME)
public @interface JsonTypeInfo

Annotation used for configuring details of if and how type information is used with JSON serialization and deserialization, to preserve information about actual class of Object instances. This is necessarily for polymorphic types, and may also be needed to link abstract declared types and matching concrete implementation.

Some examples of typical annotations:

  // Include Java class name ("com.myempl.ImplClass") as JSON property "class"
  \@JsonTypeInfo(use=Id.CLASS, include=As.PROPERTY, property="class")
  
  // Include logical type name (defined in impl classes) as wrapper; 2 annotations
  \@JsonTypeInfo(use=Id.NAME, include=As.WRAPPER_OBJECT)
  \@JsonSubTypes({com.myemp.Impl1.class, com.myempl.Impl2.class})
Alternatively you can also define fully customized type handling by using JsonTypeResolver annotation.

Since:
1.5
Author:
tatu
See Also:
JsonTypeResolver

Required Element Summary
 JsonTypeInfo.Id use
          What kind of type metadata is to be used for serializing and deserializing type information for instances of annotated type (and its subtypes unless overridden)
 
Optional Element Summary
 JsonTypeInfo.As include
          What mechanism is used for including type metadata (if any; for JsonTypeInfo.Id.NONE nothing is included).
 String property
          Property names used when type inclusion method (JsonTypeInfo.As.PROPERTY) is used (or possibly when using type metadata of type JsonTypeInfo.Id.CUSTOM).
 

Element Detail

use

public abstract JsonTypeInfo.Id use
What kind of type metadata is to be used for serializing and deserializing type information for instances of annotated type (and its subtypes unless overridden)

include

public abstract JsonTypeInfo.As include
What mechanism is used for including type metadata (if any; for JsonTypeInfo.Id.NONE nothing is included). Default

Note that for type metadata type of JsonTypeInfo.Id.CUSTOM, this setting may or may not have any effect.

Default:
org.codehaus.jackson.annotate.JsonTypeInfo.As.PROPERTY

property

public abstract String property
Property names used when type inclusion method (JsonTypeInfo.As.PROPERTY) is used (or possibly when using type metadata of type JsonTypeInfo.Id.CUSTOM).

Default property name used if this property is not explicitly defined (or is set to empty String) is based on type metadata type (use()) used.

Default:
""