public abstract class TypeSerializer
extends java.lang.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 |
---|---|
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,
java.lang.Class<?> typeForId,
JsonToken valueShape) |
WritableTypeId |
typeId(java.lang.Object value,
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) . |
WritableTypeId |
typeId(java.lang.Object value,
JsonToken valueShape,
java.lang.Object id) |
void |
writeCustomTypePrefixForArray(java.lang.Object value,
JsonGenerator g,
java.lang.String typeId)
Deprecated.
Since 2.9 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
void |
writeCustomTypePrefixForObject(java.lang.Object value,
JsonGenerator g,
java.lang.String typeId)
Deprecated.
Since 2.9 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
void |
writeCustomTypePrefixForScalar(java.lang.Object value,
JsonGenerator g,
java.lang.String typeId)
Deprecated.
Since 2.9 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
void |
writeCustomTypeSuffixForArray(java.lang.Object value,
JsonGenerator g,
java.lang.String typeId)
Deprecated.
Since 2.9 use
writeTypeSuffix(JsonGenerator, WritableTypeId) instead |
void |
writeCustomTypeSuffixForObject(java.lang.Object value,
JsonGenerator g,
java.lang.String typeId)
Deprecated.
Since 2.9 use
writeTypeSuffix(JsonGenerator, WritableTypeId) instead |
void |
writeCustomTypeSuffixForScalar(java.lang.Object value,
JsonGenerator g,
java.lang.String typeId)
Deprecated.
Since 2.9 use
writeTypeSuffix(JsonGenerator, WritableTypeId) instead |
abstract 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 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
void |
writeTypePrefixForArray(java.lang.Object value,
JsonGenerator g,
java.lang.Class<?> type)
Deprecated.
Since 2.9 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
void |
writeTypePrefixForObject(java.lang.Object value,
JsonGenerator g)
Deprecated.
Since 2.9 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
void |
writeTypePrefixForObject(java.lang.Object value,
JsonGenerator g,
java.lang.Class<?> type)
Deprecated.
Since 2.9 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
void |
writeTypePrefixForScalar(java.lang.Object value,
JsonGenerator g)
Deprecated.
Since 2.9 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
void |
writeTypePrefixForScalar(java.lang.Object value,
JsonGenerator g,
java.lang.Class<?> type)
Deprecated.
Since 2.9 use
writeTypePrefix(JsonGenerator, WritableTypeId) instead |
abstract WritableTypeId |
writeTypeSuffix(JsonGenerator g,
WritableTypeId typeId)
Method that should be called after
writeTypePrefix(JsonGenerator, WritableTypeId)
and matching value write have been called, passing WritableTypeId returned. |
void |
writeTypeSuffixForArray(java.lang.Object value,
JsonGenerator g)
Deprecated.
Since 2.9 use
writeTypeSuffix(JsonGenerator, WritableTypeId) instead |
void |
writeTypeSuffixForObject(java.lang.Object value,
JsonGenerator g)
Deprecated.
Since 2.9 use
writeTypeSuffix(JsonGenerator, WritableTypeId) instead |
void |
writeTypeSuffixForScalar(java.lang.Object value,
JsonGenerator g)
Deprecated.
Since 2.9 use
writeTypeSuffix(JsonGenerator, WritableTypeId) instead |
public abstract TypeSerializer forProperty(BeanProperty prop)
Collection
or Map
valued properties).public abstract JsonTypeInfo.As getTypeInclusion()
public abstract java.lang.String getPropertyName()
public abstract TypeIdResolver getTypeIdResolver()
public WritableTypeId typeId(java.lang.Object value, JsonToken valueShape)
writeTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
.public WritableTypeId typeId(java.lang.Object value, JsonToken valueShape, java.lang.Object id)
public WritableTypeId typeId(java.lang.Object value, java.lang.Class<?> typeForId, JsonToken valueShape)
public abstract WritableTypeId writeTypePrefix(JsonGenerator g, WritableTypeId typeId) throws java.io.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.java.io.IOException
public abstract WritableTypeId writeTypeSuffix(JsonGenerator g, WritableTypeId typeId) throws java.io.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);
java.io.IOException
@Deprecated public void writeTypePrefixForScalar(java.lang.Object value, JsonGenerator g) throws java.io.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.java.io.IOException
@Deprecated public void writeTypePrefixForObject(java.lang.Object value, JsonGenerator g) throws java.io.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.java.io.IOException
@Deprecated public void writeTypePrefixForArray(java.lang.Object value, JsonGenerator g) throws java.io.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.java.io.IOException
@Deprecated public void writeTypeSuffixForScalar(java.lang.Object value, JsonGenerator g) throws java.io.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.java.io.IOException
@Deprecated public void writeTypeSuffixForObject(java.lang.Object value, JsonGenerator g) throws java.io.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.java.io.IOException
@Deprecated public void writeTypeSuffixForArray(java.lang.Object value, JsonGenerator g) throws java.io.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.java.io.IOException
@Deprecated public void writeTypePrefixForScalar(java.lang.Object value, JsonGenerator g, java.lang.Class<?> type) throws java.io.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.java.io.IOException
@Deprecated public void writeTypePrefixForObject(java.lang.Object value, JsonGenerator g, java.lang.Class<?> type) throws java.io.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.java.io.IOException
@Deprecated public void writeTypePrefixForArray(java.lang.Object value, JsonGenerator g, java.lang.Class<?> type) throws java.io.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.java.io.IOException
@Deprecated public void writeCustomTypePrefixForScalar(java.lang.Object value, JsonGenerator g, java.lang.String typeId) throws java.io.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.java.io.IOException
@Deprecated public void writeCustomTypePrefixForObject(java.lang.Object value, JsonGenerator g, java.lang.String typeId) throws java.io.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.java.io.IOException
@Deprecated public void writeCustomTypePrefixForArray(java.lang.Object value, JsonGenerator g, java.lang.String typeId) throws java.io.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.java.io.IOException
@Deprecated public void writeCustomTypeSuffixForScalar(java.lang.Object value, JsonGenerator g, java.lang.String typeId) throws java.io.IOException
writeTypeSuffix(JsonGenerator, WritableTypeId)
insteadjava.io.IOException
@Deprecated public void writeCustomTypeSuffixForObject(java.lang.Object value, JsonGenerator g, java.lang.String typeId) throws java.io.IOException
writeTypeSuffix(JsonGenerator, WritableTypeId)
insteadjava.io.IOException
@Deprecated public void writeCustomTypeSuffixForArray(java.lang.Object value, JsonGenerator g, java.lang.String typeId) throws java.io.IOException
writeTypeSuffix(JsonGenerator, WritableTypeId)
insteadjava.io.IOException
Copyright © 2010 - 2020 Adobe. All Rights Reserved