Top Description Inners Fields Constructors Methods
com.fasterxml.jackson.core.type

public Class WritableTypeId

extends Object
Class Inheritance
Imports
com.fasterxml.jackson.core.JsonToken

This is a simple value class used between core streaming and higher level databinding to pass information about type ids to write. Properties are exposed and mutable on purpose: they are only used for communication over serialization of a single value, and neither retained across calls nor shared between threads.

Usual usage pattern is such that instance of this class is passed on two calls that are needed for outputting type id (and possible additional wrapping, depending on format; JSON, for example, requires wrapping as type id is part of regular data): first, a "prefix" write (which usually includes actual id), performed before value write; and then matching "suffix" write after value serialization.

Since
2.9

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
WritableTypeId.Inclusion

Enumeration of values that matches enum `As` from annotation `JsonTypeInfo`: separate definition to avoid dependency between streaming core and annotations packages; also allows more flexibility in case new values needed at this level of internal API.

Field Summary

Modifier and TypeField and Description
public String
asProperty

If type id is to be embedded as a regular property, name of the property; otherwise `null`.

public Object
extra

Optional additional information that generator may add during "prefix write", to be available on matching "suffix write".

public Object
forValue

Java object for which type id is being written.

public Class<?>
forValueType

(optional) Super-type of forValue to use for type id generation (if no explicit id passed): used instead of actual class of forValue in cases where we do not want to use the "real" type but something more generic, usually to work around specific problem with implementation type, or its deserializer.

public Object
id

Actual type id to use: usually {link java.lang.String}.

public WritableTypeId.Inclusion
include

Property used to indicate style of inclusion for this type id, in cases where no native type id may be used (either because format has none, like JSON; or because use of native type ids is disabled [with YAML]).

public JsonToken
valueShape

Information about intended shape of the value being written (that is, forValue); in case of structured values, start token of the structure; for scalars, value token.

public boolean
wrapperWritten

Flag that can be set to indicate that wrapper structure was written (during prefix-writing); used to determine if suffix requires matching close markers.

Constructor Summary

AccessConstructor and Description
public
public
WritableTypeId(Object
Actual value for which type information is written
value
,
JsonToken
Serialize shape writer will use for value
valueShape
)

Constructor used when calling a method for generating and writing Type Id; caller only knows value object and its intended shape.

public
WritableTypeId(Object
Actual value for which type information is written
value
,
Class<?>
Effective type of value to use for Type Id generation
valueType
,
JsonToken
Serialize shape writer will use for value
valueShape
)

Constructor used when calling a method for generating and writing Type Id, but where actual type to use for generating id is NOT the type of value (but its supertype).

public
WritableTypeId(Object
Actual value for which type information is written
value
,
JsonToken
Serialize shape writer will use for value
valueShape
,
Object
Actual type id to use if known; null if not
id
)

Constructor used when calling a method for writing Type Id; caller knows value object, its intended shape as well as id to use; but not details of wrapping (if any).

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

asPropertyback to summary
public String asProperty

If type id is to be embedded as a regular property, name of the property; otherwise `null`.

Note

if "wrap-as-Object" is used, this does NOT contain property name to use but `null`.

extraback to summary
public Object extra

Optional additional information that generator may add during "prefix write", to be available on matching "suffix write".

forValueback to summary
public Object forValue

Java object for which type id is being written. Not needed by default handling, but may be useful for customized format handling.

forValueTypeback to summary
public Class<?> forValueType

(optional) Super-type of forValue to use for type id generation (if no explicit id passed): used instead of actual class of forValue in cases where we do not want to use the "real" type but something more generic, usually to work around specific problem with implementation type, or its deserializer.

idback to summary
public Object id

Actual type id to use: usually {link java.lang.String}.

includeback to summary
public WritableTypeId.Inclusion include

Property used to indicate style of inclusion for this type id, in cases where no native type id may be used (either because format has none, like JSON; or because use of native type ids is disabled [with YAML]).

valueShapeback to summary
public JsonToken valueShape

Information about intended shape of the value being written (that is, forValue); in case of structured values, start token of the structure; for scalars, value token. Main difference is between structured values (JsonToken#START_ARRAY, JsonToken#START_OBJECT) and scalars (JsonToken#VALUE_STRING): specific scalar type may not be important for processing.

wrapperWrittenback to summary
public boolean wrapperWritten

Flag that can be set to indicate that wrapper structure was written (during prefix-writing); used to determine if suffix requires matching close markers.

Constructor Detail

WritableTypeIdback to summary
public WritableTypeId()
WritableTypeIdback to summary
public WritableTypeId(Object value, JsonToken valueShape)

Constructor used when calling a method for generating and writing Type Id; caller only knows value object and its intended shape.

Parameters
value:Object

Actual value for which type information is written

valueShape:JsonToken

Serialize shape writer will use for value

WritableTypeIdback to summary
public WritableTypeId(Object value, Class<?> valueType, JsonToken valueShape)

Constructor used when calling a method for generating and writing Type Id, but where actual type to use for generating id is NOT the type of value (but its supertype).

Parameters
value:Object

Actual value for which type information is written

valueType:Class<?>

Effective type of value to use for Type Id generation

valueShape:JsonToken

Serialize shape writer will use for value

WritableTypeIdback to summary
public WritableTypeId(Object value, JsonToken valueShape, Object id)

Constructor used when calling a method for writing Type Id; caller knows value object, its intended shape as well as id to use; but not details of wrapping (if any).

Parameters
value:Object

Actual value for which type information is written

valueShape:JsonToken

Serialize shape writer will use for value

id:Object

Actual type id to use if known; null if not

com.fasterxml.jackson.core.type back to summary

public final Enum WritableTypeId.Inclusion

extends Enum<WritableTypeId.Inclusion>
Class Inheritance

Enumeration of values that matches enum `As` from annotation `JsonTypeInfo`: separate definition to avoid dependency between streaming core and annotations packages; also allows more flexibility in case new values needed at this level of internal API.

Note

in most cases this only matters with formats that do NOT have native type id capabilities, and require type id to be included within regular data (whether exposed as Java properties or not). Formats with native types usually use native type id functionality regardless, unless overridden by a feature to use "non-native" type inclusion.

Field Summary

Modifier and TypeField and Description
public static final WritableTypeId.Inclusion
METADATA_PROPERTY

Inclusion as a property within Object to write, but logically as separate metadata that is not exposed as payload to caller: that is, does not match any of visible properties value object has.

public static final WritableTypeId.Inclusion
PARENT_PROPERTY

Inclusion as a property within "parent" Object of value Object to write.

public static final WritableTypeId.Inclusion
PAYLOAD_PROPERTY

Inclusion as a "regular" property within Object to write; this implies that its value should come from regular POJO property on serialization, and be deserialized into such property.

public static final WritableTypeId.Inclusion
WRAPPER_ARRAY

Inclusion as wrapper Array (1st element type id, 2nd element value).

public static final WritableTypeId.Inclusion
WRAPPER_OBJECT

Inclusion as wrapper Object that has one key/value pair where type id is the key for typed value.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
public static WritableTypeId.Inclusion
public static WritableTypeId.Inclusion[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

METADATA_PROPERTYback to summary
public static final WritableTypeId.Inclusion METADATA_PROPERTY

Inclusion as a property within Object to write, but logically as separate metadata that is not exposed as payload to caller: that is, does not match any of visible properties value object has.

Note

if shape of typed value to write is NOT Object, will instead use WRAPPER_ARRAY inclusion.

Corresponds to JsonTypeInfo.As.PROPERTY.

PARENT_PROPERTYback to summary
public static final WritableTypeId.Inclusion PARENT_PROPERTY

Inclusion as a property within "parent" Object of value Object to write. This typically requires slightly convoluted processing in which property that contains type id is actually written after typed value object itself is written.
Note that it is illegal to call write method if the current (parent) write context is not Object: no coercion is done for other inclusion types (unlike with other xxx_PROPERTY choices. This also means that root values MAY NOT use this type id inclusion mechanism (as they have no parent context).

Corresponds to JsonTypeInfo.As.EXTERNAL_PROPERTY.

PAYLOAD_PROPERTYback to summary
public static final WritableTypeId.Inclusion PAYLOAD_PROPERTY

Inclusion as a "regular" property within Object to write; this implies that its value should come from regular POJO property on serialization, and be deserialized into such property. This handling, however, is up to databinding.

Regarding handling, type id is ONLY written as native type id; if no native type ids available, caller is assumed to handle output some other way. This is different from METADATA_PROPERTY.

Note

if shape of typed value to write is NOT Object, will instead use WRAPPER_ARRAY inclusion.

Corresponds to JsonTypeInfo.As.EXISTING_PROPERTY.

WRAPPER_ARRAYback to summary
public static final WritableTypeId.Inclusion WRAPPER_ARRAY

Inclusion as wrapper Array (1st element type id, 2nd element value).

Corresponds to JsonTypeInfo.As.WRAPPER_ARRAY.

WRAPPER_OBJECTback to summary
public static final WritableTypeId.Inclusion WRAPPER_OBJECT

Inclusion as wrapper Object that has one key/value pair where type id is the key for typed value.

Corresponds to JsonTypeInfo.As.WRAPPER_OBJECT.

Constructor Detail

Inclusionback to summary
private Inclusion()

Method Detail

requiresObjectContextback to summary
public boolean requiresObjectContext()
valueOfback to summary
public static WritableTypeId.Inclusion valueOf(String name)
valuesback to summary
public static WritableTypeId.Inclusion[] values()