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() |
public abstract TypeSerializer forProperty(BeanProperty prop)
Collection
or Map
valued properties).public abstract JsonTypeInfo.As getTypeInclusion()
public abstract String getPropertyName()
public abstract TypeIdResolver getTypeIdResolver()
public WritableTypeId typeId(Object value, JsonToken valueShape)
writeTypePrefix(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.core.type.WritableTypeId)
.public WritableTypeId typeId(Object value, JsonToken valueShape, Object id)
public WritableTypeId typeId(Object value, Class<?> typeForId, JsonToken valueShape)
public abstract WritableTypeId writeTypePrefix(JsonGenerator g, 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 WritableTypeId writeTypeSuffix(JsonGenerator g, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, JsonGenerator g, String typeId) throws IOException
writeTypeSuffix(JsonGenerator, WritableTypeId)
insteadIOException
@Deprecated public void writeCustomTypeSuffixForObject(Object value, JsonGenerator g, String typeId) throws IOException
writeTypeSuffix(JsonGenerator, WritableTypeId)
insteadIOException
@Deprecated public void writeCustomTypeSuffixForArray(Object value, JsonGenerator g, String typeId) throws IOException
writeTypeSuffix(JsonGenerator, WritableTypeId)
insteadIOException
protected final void _writeLegacySuffix(JsonGenerator g, WritableTypeId typeId) throws IOException
IOException
Copyright © 2019 JBoss by Red Hat. All rights reserved.