java.lang.Object
tools.jackson.databind.ValueSerializer<T>
tools.jackson.databind.ser.std.StdSerializer<T>
tools.jackson.databind.ser.std.StdScalarSerializer<Enum<?>>
tools.jackson.databind.ser.jdk.EnumSerializer
- All Implemented Interfaces:
JsonFormatVisitable
Standard serializer used for
Enum
types.
Based on StdScalarSerializer
since the JSON value is
scalar (String).
-
Nested Class Summary
Nested classes/interfaces inherited from class tools.jackson.databind.ValueSerializer
ValueSerializer.None
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Boolean
Flag that is set if we statically know serialization choice between index and textual format (null if it needs to be dynamically checked).protected final EnumValues
This map contains pre-resolved values (since there are ways to customize actual String constants to use) to use as serializations.protected final EnumValues
Map with key as converted property class defined implementation ofEnumNamingStrategy
and with value as Enum names collected usingEnum.name()
.protected final EnumValues
Map that contains pre-resolved values forEnum.toString()
to use for serialization, while respectingJsonProperty
andEnumFeature.WRITE_ENUMS_TO_LOWERCASE
.Fields inherited from class tools.jackson.databind.ser.std.StdSerializer
_handledType
-
Constructor Summary
ConstructorsConstructorDescriptionEnumSerializer
(EnumValues v, Boolean serializeAsIndex, EnumValues valuesByEnumNaming, EnumValues valuesByToString) -
Method Summary
Modifier and TypeMethodDescriptionprotected static Boolean
_isShapeWrittenUsingIndex
(Class<?> enumClass, JsonFormat.Value format, boolean fromClass, Boolean defaultValue) Helper method called to check whether serialization should be done using index (number) or not.protected final boolean
void
acceptJsonFormatVisitor
(JsonFormatVisitorWrapper visitor, JavaType typeHint) Default implementation specifies no format.static EnumSerializer
construct
(Class<?> enumClass, SerializationConfig config, BeanDescription beanDesc, JsonFormat.Value format) Factory method used byBasicSerializerFactory
for constructing serializer instance of Enum types.protected static EnumValues
constructEnumNamingStrategyValues
(SerializationConfig config, Class<Enum<?>> enumClass, AnnotatedClass annotatedClass) Factory method used to resolve an instance ofEnumValues
withEnumNamingStrategy
applied for the target class.createContextual
(SerializationContext ctxt, BeanProperty property) To support some level of per-property configuration, we will need to make things contextual.final void
serialize
(Enum<?> en, JsonGenerator g, SerializationContext ctxt) Method that can be called to ask implementation to serialize values of type this serializer handles.Methods inherited from class tools.jackson.databind.ser.std.StdScalarSerializer
serializeWithType
Methods inherited from class tools.jackson.databind.ser.std.StdSerializer
_neitherNull, _nonEmpty, _wrapIOFailure, acceptJsonFormatVisitorForBinary, createSchemaNode, createSchemaNode, findAnnotatedContentSerializer, findContextualConvertingSerializer, findFormatFeature, findFormatOverrides, findIncludeOverrides, findPropertyFilter, handledType, isDefaultSerializer, visitArrayFormat, visitArrayFormat, visitFloatFormat, visitIntFormat, visitIntFormat, visitStringFormat, visitStringFormat, wrapAndThrow, wrapAndThrow
Methods inherited from class tools.jackson.databind.ValueSerializer
getDelegatee, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, resolve, unwrappingSerializer, usesObjectId, withFilterId, withFormatOverrides, withIgnoredProperties
-
Field Details
-
_values
This map contains pre-resolved values (since there are ways to customize actual String constants to use) to use as serializations. -
_serializeAsIndex
Flag that is set if we statically know serialization choice between index and textual format (null if it needs to be dynamically checked). -
_valuesByEnumNaming
Map with key as converted property class defined implementation ofEnumNamingStrategy
and with value as Enum names collected usingEnum.name()
. -
_valuesByToString
Map that contains pre-resolved values forEnum.toString()
to use for serialization, while respectingJsonProperty
andEnumFeature.WRITE_ENUMS_TO_LOWERCASE
.
-
-
Constructor Details
-
EnumSerializer
public EnumSerializer(EnumValues v, Boolean serializeAsIndex, EnumValues valuesByEnumNaming, EnumValues valuesByToString)
-
-
Method Details
-
construct
public static EnumSerializer construct(Class<?> enumClass, SerializationConfig config, BeanDescription beanDesc, JsonFormat.Value format) Factory method used byBasicSerializerFactory
for constructing serializer instance of Enum types. -
createContextual
To support some level of per-property configuration, we will need to make things contextual. We are limited to "textual vs index" choice here, however.- Overrides:
createContextual
in classValueSerializer<Enum<?>>
- Parameters:
ctxt
- Context to use for accessing config, other serializersproperty
- Property (defined by one or more accessors - field or method - used for accessing logical property value) for which serializer is used to be used; or, `null` for root value (or in cases where caller does not have this information, which is handled as root value case).- Returns:
- Serializer to use for serializing values of specified property; may be this instance or a new instance.
-
getEnumValues
-
serialize
public final void serialize(Enum<?> en, JsonGenerator g, SerializationContext ctxt) throws JacksonException Description copied from class:ValueSerializer
Method that can be called to ask implementation to serialize values of type this serializer handles.- Specified by:
serialize
in classStdSerializer<Enum<?>>
- Parameters:
en
- Value to serialize; can not be null.g
- Generator used to output resulting Json contentctxt
- Context that can be used to get serializers for serializing Objects value contains, if any.- Throws:
JacksonException
-
acceptJsonFormatVisitor
Description copied from class:StdSerializer
Default implementation specifies no format. This behavior is usually overriden by custom serializers.- Specified by:
acceptJsonFormatVisitor
in interfaceJsonFormatVisitable
- Overrides:
acceptJsonFormatVisitor
in classStdScalarSerializer<Enum<?>>
typeHint
- Type of element (entity like property) being visited
-
_serializeAsIndex
-
_isShapeWrittenUsingIndex
protected static Boolean _isShapeWrittenUsingIndex(Class<?> enumClass, JsonFormat.Value format, boolean fromClass, Boolean defaultValue) Helper method called to check whether serialization should be done using index (number) or not. -
constructEnumNamingStrategyValues
protected static EnumValues constructEnumNamingStrategyValues(SerializationConfig config, Class<Enum<?>> enumClass, AnnotatedClass annotatedClass) Factory method used to resolve an instance ofEnumValues
withEnumNamingStrategy
applied for the target class.
-