Class TypeSerializer
- java.lang.Object
-
- com.fasterxml.jackson.databind.jsontype.TypeSerializer
-
- Direct Known Subclasses:
TypeSerializerBase
public abstract class TypeSerializer extends java.lang.Object
Interface for serializing type information regarding instances of specified base type (super class), so that exact subtype can be properly deserialized later on. These instances are to be called by regularJsonSerializer
s using proper contextual calls, to add type information using mechanism type serializer was configured with.NOTE: version 2.9 contains significant attempt at simplifying interface, as well as giving format implementation (via
JsonGenerator
) more control over actual serialization details. Minor changes are required to change call pattern so that return value of "prefix" write needs to be passed to "suffix" write.
-
-
Constructor Summary
Constructors Constructor Description TypeSerializer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract TypeSerializer
forProperty(BeanProperty prop)
Method called to create contextual version, to be used for values of given property.abstract java.lang.String
getPropertyName()
Name of property that contains type information, if property-based inclusion is used.abstract TypeIdResolver
getTypeIdResolver()
Accessor for object that handles conversions between types and matching type ids.abstract JsonTypeInfo.As
getTypeInclusion()
Accessor for type information inclusion method that serializer uses; indicates how type information is embedded in resulting JSON.WritableTypeId
typeId(java.lang.Object value, JsonToken valueShape)
Factory method for constructing type id value object to pass towriteTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
.WritableTypeId
typeId(java.lang.Object value, JsonToken valueShape, java.lang.Object id)
WritableTypeId
typeId(java.lang.Object value, java.lang.Class<?> typeForId, JsonToken valueShape)
void
writeCustomTypePrefixForArray(java.lang.Object value, JsonGenerator g, java.lang.String typeId)
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadvoid
writeCustomTypePrefixForObject(java.lang.Object value, JsonGenerator g, java.lang.String typeId)
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadvoid
writeCustomTypePrefixForScalar(java.lang.Object value, JsonGenerator g, java.lang.String typeId)
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadvoid
writeCustomTypeSuffixForArray(java.lang.Object value, JsonGenerator g, java.lang.String typeId)
Deprecated.Since 2.9 usewriteTypeSuffix(JsonGenerator, WritableTypeId)
insteadvoid
writeCustomTypeSuffixForObject(java.lang.Object value, JsonGenerator g, java.lang.String typeId)
Deprecated.Since 2.9 usewriteTypeSuffix(JsonGenerator, WritableTypeId)
insteadvoid
writeCustomTypeSuffixForScalar(java.lang.Object value, JsonGenerator g, java.lang.String typeId)
Deprecated.Since 2.9 usewriteTypeSuffix(JsonGenerator, WritableTypeId)
insteadabstract WritableTypeId
writeTypePrefix(JsonGenerator g, WritableTypeId typeId)
Method called to write initial part of type information for given value, along with possible wrapping to use: details are specified by `typeId` argument.void
writeTypePrefixForArray(java.lang.Object value, JsonGenerator g)
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadvoid
writeTypePrefixForArray(java.lang.Object value, JsonGenerator g, java.lang.Class<?> type)
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadvoid
writeTypePrefixForObject(java.lang.Object value, JsonGenerator g)
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadvoid
writeTypePrefixForObject(java.lang.Object value, JsonGenerator g, java.lang.Class<?> type)
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadvoid
writeTypePrefixForScalar(java.lang.Object value, JsonGenerator g)
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadvoid
writeTypePrefixForScalar(java.lang.Object value, JsonGenerator g, java.lang.Class<?> type)
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadabstract WritableTypeId
writeTypeSuffix(JsonGenerator g, WritableTypeId typeId)
Method that should be called afterwriteTypePrefix(JsonGenerator, WritableTypeId)
and matching value write have been called, passingWritableTypeId
returned.void
writeTypeSuffixForArray(java.lang.Object value, JsonGenerator g)
Deprecated.Since 2.9 usewriteTypeSuffix(JsonGenerator, WritableTypeId)
insteadvoid
writeTypeSuffixForObject(java.lang.Object value, JsonGenerator g)
Deprecated.Since 2.9 usewriteTypeSuffix(JsonGenerator, WritableTypeId)
insteadvoid
writeTypeSuffixForScalar(java.lang.Object value, JsonGenerator g)
Deprecated.Since 2.9 usewriteTypeSuffix(JsonGenerator, WritableTypeId)
instead
-
-
-
Method Detail
-
forProperty
public abstract TypeSerializer forProperty(BeanProperty prop)
Method called to create contextual version, to be used for values of given property. This may be the type itself (as is the case for bean properties), or values contained (forCollection
orMap
valued properties).- Since:
- 2.0
-
getTypeInclusion
public abstract JsonTypeInfo.As getTypeInclusion()
Accessor for type information inclusion method that serializer uses; indicates how type information is embedded in resulting JSON.
-
getPropertyName
public abstract java.lang.String getPropertyName()
Name of property that contains type information, if property-based inclusion is used.
-
getTypeIdResolver
public abstract TypeIdResolver getTypeIdResolver()
Accessor for object that handles conversions between types and matching type ids.
-
typeId
public WritableTypeId typeId(java.lang.Object value, JsonToken valueShape)
Factory method for constructing type id value object to pass towriteTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
.
-
typeId
public WritableTypeId typeId(java.lang.Object value, JsonToken valueShape, java.lang.Object id)
-
typeId
public WritableTypeId typeId(java.lang.Object value, java.lang.Class<?> typeForId, JsonToken valueShape)
-
writeTypePrefix
public abstract WritableTypeId writeTypePrefix(JsonGenerator g, WritableTypeId typeId) throws java.io.IOException
Method called to write initial part of type information for given value, along with possible wrapping to use: details are specified by `typeId` argument. Note that for structured types (Object, Array), this call will add necessary start token so it should NOT be explicitly written, unlike with non-type-id value writes.See
writeTypeSuffix(JsonGenerator, WritableTypeId)
for a complete example of typical usage.- Parameters:
g
- Generator to use for outputting type id and possible wrappingtypeId
- Details of what type id is to be written, how.- Throws:
java.io.IOException
- Since:
- 2.9
-
writeTypeSuffix
public abstract WritableTypeId writeTypeSuffix(JsonGenerator g, WritableTypeId typeId) throws java.io.IOException
Method that should be called afterwriteTypePrefix(JsonGenerator, WritableTypeId)
and matching value write have been called, passingWritableTypeId
returned. Usual idiom is:// Indicator generator that type identifier may be needed; generator may write // one as suggested, modify information, or take some other action // NOTE! For Object/Array types, this will ALSO write start marker! WritableTypeId typeIdDef = typeSer.writeTypePrefix(gen, typeSer.typeId(value, JsonToken.START_OBJECT)); // serializing actual value for which TypeId may have been written... like // NOTE: do NOT write START_OBJECT before OR END_OBJECT after: g.writeStringField("message", "Hello, world!" // matching type suffix call to let generator chance to add suffix, if any // NOTE! For Object/Array types, this will ALSO write end marker! typeSer.writeTypeSuffix(gen, typeIdDef);
- Throws:
java.io.IOException
- Since:
- 2.9
-
writeTypePrefixForScalar
@Deprecated public void writeTypePrefixForScalar(java.lang.Object value, JsonGenerator g) throws java.io.IOException
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadDEPRECATED: now equivalent to:writeTypePrefix(g, typeId(value, JsonToken.VALUE_STRING));
. SeewriteTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.- Throws:
java.io.IOException
-
writeTypePrefixForObject
@Deprecated public void writeTypePrefixForObject(java.lang.Object value, JsonGenerator g) throws java.io.IOException
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadDEPRECATED: now equivalent to:writeTypePrefix(g, typeId(value, JsonToken.START_OBJECT));
. SeewriteTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.- Throws:
java.io.IOException
-
writeTypePrefixForArray
@Deprecated public void writeTypePrefixForArray(java.lang.Object value, JsonGenerator g) throws java.io.IOException
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadDEPRECATED: now equivalent to:writeTypePrefix(g, typeId(value, JsonToken.START_ARRAY));
. SeewriteTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.- Throws:
java.io.IOException
-
writeTypeSuffixForScalar
@Deprecated public void writeTypeSuffixForScalar(java.lang.Object value, JsonGenerator g) throws java.io.IOException
Deprecated.Since 2.9 usewriteTypeSuffix(JsonGenerator, WritableTypeId)
insteadDEPRECATED: now equivalent to:writeTypeSuffix(g, typeId(value, JsonToken.VALUE_STRING));
. SeewriteTypeSuffix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.- Throws:
java.io.IOException
-
writeTypeSuffixForObject
@Deprecated public void writeTypeSuffixForObject(java.lang.Object value, JsonGenerator g) throws java.io.IOException
Deprecated.Since 2.9 usewriteTypeSuffix(JsonGenerator, WritableTypeId)
insteadDEPRECATED: now equivalent to:writeTypeSuffix(g, typeId(value, JsonToken.START_OBJECT));
. SeewriteTypeSuffix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.- Throws:
java.io.IOException
-
writeTypeSuffixForArray
@Deprecated public void writeTypeSuffixForArray(java.lang.Object value, JsonGenerator g) throws java.io.IOException
Deprecated.Since 2.9 usewriteTypeSuffix(JsonGenerator, WritableTypeId)
insteadDEPRECATED: now equivalent to:writeTypeSuffix(g, typeId(value, JsonToken.START_ARRAY));
. SeewriteTypeSuffix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.- Throws:
java.io.IOException
-
writeTypePrefixForScalar
@Deprecated public void writeTypePrefixForScalar(java.lang.Object value, JsonGenerator g, java.lang.Class<?> type) throws java.io.IOException
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadDEPRECATED: now equivalent to:writeTypePrefix(g, typeId(value, type, JsonToken.VALUE_STRING));
. SeewriteTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.- Throws:
java.io.IOException
-
writeTypePrefixForObject
@Deprecated public void writeTypePrefixForObject(java.lang.Object value, JsonGenerator g, java.lang.Class<?> type) throws java.io.IOException
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadDEPRECATED: now equivalent to:writeTypePrefix(g, typeId(value, type, JsonToken.START_OBJECT));
. SeewriteTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.- Throws:
java.io.IOException
-
writeTypePrefixForArray
@Deprecated public void writeTypePrefixForArray(java.lang.Object value, JsonGenerator g, java.lang.Class<?> type) throws java.io.IOException
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadDEPRECATED: now equivalent to:writeTypePrefix(g, typeId(value, type, JsonToken.START_ARRAY));
. SeewriteTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.- Throws:
java.io.IOException
-
writeCustomTypePrefixForScalar
@Deprecated public void writeCustomTypePrefixForScalar(java.lang.Object value, JsonGenerator g, java.lang.String typeId) throws java.io.IOException
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadDEPRECATED: now equivalent to:writeTypePrefix(g, typeId(value, JsonToken.VALUE_STRING, typeId));
. SeewriteTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.- Throws:
java.io.IOException
-
writeCustomTypePrefixForObject
@Deprecated public void writeCustomTypePrefixForObject(java.lang.Object value, JsonGenerator g, java.lang.String typeId) throws java.io.IOException
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadDEPRECATED: now equivalent to:writeTypePrefix(g, typeId(value, JsonToken.START_OBJECT, typeId));
. SeewriteTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.- Throws:
java.io.IOException
-
writeCustomTypePrefixForArray
@Deprecated public void writeCustomTypePrefixForArray(java.lang.Object value, JsonGenerator g, java.lang.String typeId) throws java.io.IOException
Deprecated.Since 2.9 usewriteTypePrefix(JsonGenerator, WritableTypeId)
insteadDEPRECATED: now equivalent to:writeTypePrefix(g, typeId(value, JsonToken.START_ARRAY, typeId));
. SeewriteTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.- Throws:
java.io.IOException
-
writeCustomTypeSuffixForScalar
@Deprecated public void writeCustomTypeSuffixForScalar(java.lang.Object value, JsonGenerator g, java.lang.String typeId) throws java.io.IOException
Deprecated.Since 2.9 usewriteTypeSuffix(JsonGenerator, WritableTypeId)
instead- Throws:
java.io.IOException
-
writeCustomTypeSuffixForObject
@Deprecated public void writeCustomTypeSuffixForObject(java.lang.Object value, JsonGenerator g, java.lang.String typeId) throws java.io.IOException
Deprecated.Since 2.9 usewriteTypeSuffix(JsonGenerator, WritableTypeId)
instead- Throws:
java.io.IOException
-
writeCustomTypeSuffixForArray
@Deprecated public void writeCustomTypeSuffixForArray(java.lang.Object value, JsonGenerator g, java.lang.String typeId) throws java.io.IOException
Deprecated.Since 2.9 usewriteTypeSuffix(JsonGenerator, WritableTypeId)
instead- Throws:
java.io.IOException
-
-