Package com.fasterxml.jackson.core.type
Class WritableTypeId
- java.lang.Object
-
- com.fasterxml.jackson.core.type.WritableTypeId
-
public class WritableTypeId extends java.lang.Object
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 Class Summary
Nested Classes Modifier and Type Class Description static class
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
Fields Modifier and Type Field Description java.lang.String
asProperty
If type id is to be embedded as a regular property, name of the property; otherwise `null`.java.lang.Object
extra
Optional additional information that generator may add during "prefix write", to be available on matching "suffix write".java.lang.Object
forValue
Java object for which type id is being written.java.lang.Class<?>
forValueType
(optional) Super-type offorValue
to use for type id generation (if no explicit id passed): used instead of actual class offorValue
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.java.lang.Object
id
Actual type id to use: usually {link java.lang.String}.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]).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.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
Constructors Constructor Description WritableTypeId()
WritableTypeId(java.lang.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.WritableTypeId(java.lang.Object value, JsonToken valueShape, java.lang.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).WritableTypeId(java.lang.Object value, java.lang.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).
-
-
-
Field Detail
-
forValue
public java.lang.Object forValue
Java object for which type id is being written. Not needed by default handling, but may be useful for customized format handling.
-
forValueType
public java.lang.Class<?> forValueType
(optional) Super-type offorValue
to use for type id generation (if no explicit id passed): used instead of actual class offorValue
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.
-
id
public java.lang.Object id
Actual type id to use: usually {link java.lang.String}.
-
asProperty
public java.lang.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`.
-
include
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]).
-
valueShape
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.
-
wrapperWritten
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.
-
extra
public java.lang.Object extra
Optional additional information that generator may add during "prefix write", to be available on matching "suffix write".
-
-
Constructor Detail
-
WritableTypeId
public WritableTypeId()
-
WritableTypeId
public WritableTypeId(java.lang.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
- Actual value for which type information is writtenvalueShape
- Serialize shape writer will use for value
-
WritableTypeId
public WritableTypeId(java.lang.Object value, java.lang.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
- Actual value for which type information is writtenvalueType
- Effective type ofvalue
to use for Type Id generationvalueShape
- Serialize shape writer will use for value
-
WritableTypeId
public WritableTypeId(java.lang.Object value, JsonToken valueShape, java.lang.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
- Actual value for which type information is writtenvalueShape
- Serialize shape writer will use for valueid
- Actual type id to use if known;null
if not
-
-