public abstract class TypeSerializer extends Object
JsonSerializer
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 and Description |
---|
TypeSerializer() |
Modifier and Type | Method and Description |
---|---|
protected void |
_writeLegacySuffix(com.fasterxml.jackson.core.JsonGenerator g,
com.fasterxml.jackson.core.type.WritableTypeId typeId)
Helper method needed for backwards compatibility: since original type id
can not be routed through completely, we have to reverse-engineer likely
setting before calling suffix.
|
abstract TypeSerializer |
forProperty(BeanProperty prop)
Method called to create contextual version, to be used for
values of given property.
|
abstract 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 com.fasterxml.jackson.annotation.JsonTypeInfo.As |
getTypeInclusion()
Accessor for type information inclusion method
that serializer uses; indicates how type information
is embedded in resulting JSON.
|
com.fasterxml.jackson.core.type.WritableTypeId |
typeId(Object value,
Class<?> typeForId,
com.fasterxml.jackson.core.JsonToken valueShape) |
com.fasterxml.jackson.core.type.WritableTypeId |
typeId(Object value,
com.fasterxml.jackson.core.JsonToken valueShape)
Factory method for constructing type id value object to pass to
writeTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId) . |
com.fasterxml.jackson.core.type.WritableTypeId |
typeId(Object value,
com.fasterxml.jackson.core.JsonToken valueShape,
Object id) |
void |
writeCustomTypePrefixForArray(Object value,
com.fasterxml.jackson.core.JsonGenerator g,
String typeId)
Deprecated.
Since 2.9 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
void |
writeCustomTypePrefixForObject(Object value,
com.fasterxml.jackson.core.JsonGenerator g,
String typeId)
Deprecated.
Since 2.9 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
void |
writeCustomTypePrefixForScalar(Object value,
com.fasterxml.jackson.core.JsonGenerator g,
String typeId)
Deprecated.
Since 2.9 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
void |
writeCustomTypeSuffixForArray(Object value,
com.fasterxml.jackson.core.JsonGenerator g,
String typeId)
Deprecated.
Since 2.9 use
writeTypeSuffix(JsonGenerator, WritableTypeId) instead |
void |
writeCustomTypeSuffixForObject(Object value,
com.fasterxml.jackson.core.JsonGenerator g,
String typeId)
Deprecated.
Since 2.9 use
writeTypeSuffix(JsonGenerator, WritableTypeId) instead |
void |
writeCustomTypeSuffixForScalar(Object value,
com.fasterxml.jackson.core.JsonGenerator g,
String typeId)
Deprecated.
Since 2.9 use
writeTypeSuffix(JsonGenerator, WritableTypeId) instead |
abstract com.fasterxml.jackson.core.type.WritableTypeId |
writeTypePrefix(com.fasterxml.jackson.core.JsonGenerator g,
com.fasterxml.jackson.core.type.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(Object value,
com.fasterxml.jackson.core.JsonGenerator g)
Deprecated.
Since 2.9 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
void |
writeTypePrefixForArray(Object value,
com.fasterxml.jackson.core.JsonGenerator g,
Class<?> type)
Deprecated.
Since 2.9 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
void |
writeTypePrefixForObject(Object value,
com.fasterxml.jackson.core.JsonGenerator g)
Deprecated.
Since 2.9 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
void |
writeTypePrefixForObject(Object value,
com.fasterxml.jackson.core.JsonGenerator g,
Class<?> type)
Deprecated.
Since 2.9 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
void |
writeTypePrefixForScalar(Object value,
com.fasterxml.jackson.core.JsonGenerator g)
Deprecated.
Since 2.9 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
void |
writeTypePrefixForScalar(Object value,
com.fasterxml.jackson.core.JsonGenerator g,
Class<?> type)
Deprecated.
Since 2.9 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
abstract com.fasterxml.jackson.core.type.WritableTypeId |
writeTypeSuffix(com.fasterxml.jackson.core.JsonGenerator g,
com.fasterxml.jackson.core.type.WritableTypeId typeId)
Method that should be called after
writeTypePrefix(JsonGenerator, WritableTypeId)
and matching value write have been called, passing WritableTypeId returned. |
void |
writeTypeSuffixForArray(Object value,
com.fasterxml.jackson.core.JsonGenerator g)
Deprecated.
Since 2.9 use
writeTypeSuffix(JsonGenerator, WritableTypeId) instead |
void |
writeTypeSuffixForObject(Object value,
com.fasterxml.jackson.core.JsonGenerator g)
Deprecated.
Since 2.9 use
writeTypeSuffix(JsonGenerator, WritableTypeId) instead |
void |
writeTypeSuffixForScalar(Object value,
com.fasterxml.jackson.core.JsonGenerator g)
Deprecated.
Since 2.9 use
writeTypeSuffix(JsonGenerator, WritableTypeId) instead |
public abstract TypeSerializer forProperty(BeanProperty prop)
Collection
or Map
valued properties).public abstract com.fasterxml.jackson.annotation.JsonTypeInfo.As getTypeInclusion()
public abstract String getPropertyName()
public abstract TypeIdResolver getTypeIdResolver()
public com.fasterxml.jackson.core.type.WritableTypeId typeId(Object value, com.fasterxml.jackson.core.JsonToken valueShape)
writeTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
.public com.fasterxml.jackson.core.type.WritableTypeId typeId(Object value, com.fasterxml.jackson.core.JsonToken valueShape, Object id)
public com.fasterxml.jackson.core.type.WritableTypeId typeId(Object value, Class<?> typeForId, com.fasterxml.jackson.core.JsonToken valueShape)
public abstract com.fasterxml.jackson.core.type.WritableTypeId writeTypePrefix(com.fasterxml.jackson.core.JsonGenerator g, com.fasterxml.jackson.core.type.WritableTypeId typeId) throws IOException
See writeTypeSuffix(JsonGenerator, WritableTypeId)
for a complete
example of typical usage.
g
- Generator to use for outputting type id and possible wrappingtypeId
- Details of what type id is to be written, how.IOException
public abstract com.fasterxml.jackson.core.type.WritableTypeId writeTypeSuffix(com.fasterxml.jackson.core.JsonGenerator g, com.fasterxml.jackson.core.type.WritableTypeId typeId) throws IOException
writeTypePrefix(JsonGenerator, WritableTypeId)
and matching value write have been called, passing WritableTypeId
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);
IOException
@Deprecated public void writeTypePrefixForScalar(Object value, com.fasterxml.jackson.core.JsonGenerator g) throws IOException
writeTypePrefix(JsonGenerator, WritableTypeId)
insteadwriteTypePrefix(g, typeId(value, JsonToken.VALUE_STRING));
.
See writeTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.IOException
@Deprecated public void writeTypePrefixForObject(Object value, com.fasterxml.jackson.core.JsonGenerator g) throws IOException
writeTypePrefix(JsonGenerator, WritableTypeId)
insteadwriteTypePrefix(g, typeId(value, JsonToken.START_OBJECT));
.
See writeTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.IOException
@Deprecated public void writeTypePrefixForArray(Object value, com.fasterxml.jackson.core.JsonGenerator g) throws IOException
writeTypePrefix(JsonGenerator, WritableTypeId)
insteadwriteTypePrefix(g, typeId(value, JsonToken.START_ARRAY));
.
See writeTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.IOException
@Deprecated public void writeTypeSuffixForScalar(Object value, com.fasterxml.jackson.core.JsonGenerator g) throws IOException
writeTypeSuffix(JsonGenerator, WritableTypeId)
insteadwriteTypeSuffix(g, typeId(value, JsonToken.VALUE_STRING));
.
See writeTypeSuffix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.IOException
@Deprecated public void writeTypeSuffixForObject(Object value, com.fasterxml.jackson.core.JsonGenerator g) throws IOException
writeTypeSuffix(JsonGenerator, WritableTypeId)
insteadwriteTypeSuffix(g, typeId(value, JsonToken.START_OBJECT));
.
See writeTypeSuffix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.IOException
@Deprecated public void writeTypeSuffixForArray(Object value, com.fasterxml.jackson.core.JsonGenerator g) throws IOException
writeTypeSuffix(JsonGenerator, WritableTypeId)
insteadwriteTypeSuffix(g, typeId(value, JsonToken.START_ARRAY));
.
See writeTypeSuffix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.IOException
@Deprecated public void writeTypePrefixForScalar(Object value, com.fasterxml.jackson.core.JsonGenerator g, Class<?> type) throws IOException
writeTypePrefix(JsonGenerator, WritableTypeId)
insteadwriteTypePrefix(g, typeId(value, type, JsonToken.VALUE_STRING));
.
See writeTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.IOException
@Deprecated public void writeTypePrefixForObject(Object value, com.fasterxml.jackson.core.JsonGenerator g, Class<?> type) throws IOException
writeTypePrefix(JsonGenerator, WritableTypeId)
insteadwriteTypePrefix(g, typeId(value, type, JsonToken.START_OBJECT));
.
See writeTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.IOException
@Deprecated public void writeTypePrefixForArray(Object value, com.fasterxml.jackson.core.JsonGenerator g, Class<?> type) throws IOException
writeTypePrefix(JsonGenerator, WritableTypeId)
insteadwriteTypePrefix(g, typeId(value, type, JsonToken.START_ARRAY));
.
See writeTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.IOException
@Deprecated public void writeCustomTypePrefixForScalar(Object value, com.fasterxml.jackson.core.JsonGenerator g, String typeId) throws IOException
writeTypePrefix(JsonGenerator, WritableTypeId)
insteadwriteTypePrefix(g, typeId(value, JsonToken.VALUE_STRING, typeId));
.
See writeTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.IOException
@Deprecated public void writeCustomTypePrefixForObject(Object value, com.fasterxml.jackson.core.JsonGenerator g, String typeId) throws IOException
writeTypePrefix(JsonGenerator, WritableTypeId)
insteadwriteTypePrefix(g, typeId(value, JsonToken.START_OBJECT, typeId));
.
See writeTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.IOException
@Deprecated public void writeCustomTypePrefixForArray(Object value, com.fasterxml.jackson.core.JsonGenerator g, String typeId) throws IOException
writeTypePrefix(JsonGenerator, WritableTypeId)
insteadwriteTypePrefix(g, typeId(value, JsonToken.START_ARRAY, typeId));
.
See writeTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
for more info.IOException
@Deprecated public void writeCustomTypeSuffixForScalar(Object value, com.fasterxml.jackson.core.JsonGenerator g, String typeId) throws IOException
writeTypeSuffix(JsonGenerator, WritableTypeId)
insteadIOException
@Deprecated public void writeCustomTypeSuffixForObject(Object value, com.fasterxml.jackson.core.JsonGenerator g, String typeId) throws IOException
writeTypeSuffix(JsonGenerator, WritableTypeId)
insteadIOException
@Deprecated public void writeCustomTypeSuffixForArray(Object value, com.fasterxml.jackson.core.JsonGenerator g, String typeId) throws IOException
writeTypeSuffix(JsonGenerator, WritableTypeId)
insteadIOException
protected final void _writeLegacySuffix(com.fasterxml.jackson.core.JsonGenerator g, com.fasterxml.jackson.core.type.WritableTypeId typeId) throws IOException
IOException
Copyright © 2008–2022 FasterXML. All rights reserved.