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 EnumValuesToWriteContainer for dynamically resolved serializations for the type.protected final BooleanIf statically known, whether to serialize as numeric index (TRUE) or as textual name (FALSE).Fields inherited from class tools.jackson.databind.ser.std.StdSerializer
_handledType -
Constructor Summary
ConstructorsConstructorDescriptionEnumSerializer(EnumValuesToWrite enumValuesToWrite, Boolean serializeAsNumber) -
Method Summary
Modifier and TypeMethodDescriptionprotected static Boolean_isShapeWrittenUsingNumber(Class<?> enumClass, JsonFormat.Value format, boolean fromClass, Boolean defaultValue) Helper method called to check whether serialization should be done using numeric representation or not.protected final booleanvoidacceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) Default implementation specifies no format.static EnumSerializerconstruct(Class<?> enumClass, SerializationConfig config, BeanDescription beanDesc, JsonFormat.Value format) Factory method used byBasicSerializerFactoryfor constructing serializer instance of Enum types.createContextual(SerializationContext ctxt, BeanProperty property) To support some level of per-property configuration, we will need to make things contextual.Deprecated.voidserialize(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
serializeWithTypeMethods 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, wrapAndThrowMethods inherited from class tools.jackson.databind.ValueSerializer
getDelegatee, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, resolve, unwrappingSerializer, usesObjectId, withFilterId, withFormatOverrides, withIgnoredProperties
-
Field Details
-
_enumValuesToWrite
Container for dynamically resolved serializations for the type. -
_serializeAsNumber
If statically known, whether to serialize as numeric index (TRUE) or as textual name (FALSE).nullmeans not statically known: falls back to globalEnumFeature.WRITE_ENUMS_USING_INDEXat runtime.Note: when
TRUE(explicitShape.NUMBER), numeric@JsonPropertyvalues are used as indexes; non-numeric values are written as-is (as Strings). Whennulland the global feature is enabled, ordinal is always used.- Since:
- 3.2 (renamed from earlier
_serializeAsIndex)
-
-
Constructor Details
-
EnumSerializer
-
-
Method Details
-
construct
public static EnumSerializer construct(Class<?> enumClass, SerializationConfig config, BeanDescription beanDesc, JsonFormat.Value format) Factory method used byBasicSerializerFactoryfor 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 numeric" choice here, however.- Overrides:
createContextualin 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
Deprecated. -
serialize
public void serialize(Enum<?> en, JsonGenerator g, SerializationContext ctxt) throws JacksonException Description copied from class:ValueSerializerMethod that can be called to ask implementation to serialize values of type this serializer handles.- Specified by:
serializein 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:StdSerializerDefault implementation specifies no format. This behavior is usually overriden by custom serializers.- Specified by:
acceptJsonFormatVisitorin interfaceJsonFormatVisitable- Overrides:
acceptJsonFormatVisitorin classStdScalarSerializer<Enum<?>>typeHint- Type of element (entity like property) being visited
-
_serializeAsNumber
-
_isShapeWrittenUsingNumber
protected static Boolean _isShapeWrittenUsingNumber(Class<?> enumClass, JsonFormat.Value format, boolean fromClass, Boolean defaultValue) Helper method called to check whether serialization should be done using numeric representation or not.
-