Class EnumSerializer
- java.lang.Object
-
- com.fasterxml.jackson.databind.JsonSerializer<T>
-
- com.fasterxml.jackson.databind.ser.std.StdSerializer<T>
-
- com.fasterxml.jackson.databind.ser.std.StdScalarSerializer<java.lang.Enum<?>>
-
- com.fasterxml.jackson.databind.ser.std.EnumSerializer
-
- All Implemented Interfaces:
JsonFormatVisitable,SchemaAware,ContextualSerializer,java.io.Serializable
public class EnumSerializer extends StdScalarSerializer<java.lang.Enum<?>> implements ContextualSerializer
Standard serializer used forEnumtypes.Based on
StdScalarSerializersince the JSON value is scalar (String).- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonSerializer
JsonSerializer.None
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Boolean_serializeAsIndexFlag that is set if we statically know serialization choice between index and textual format (null if it needs to be dynamically checked).protected EnumValues_valuesThis map contains pre-resolved values (since there are ways to customize actual String constants to use) to use as serializations.protected EnumValues_valuesByEnumNamingMap with key as converted property class defined implementation ofEnumNamingStrategyand with value as Enum names collected usingEnum.name().protected EnumValues_valuesByToStringMap that contains pre-resolved values forEnum.toString()to use for serialization, while respectingJsonPropertyandEnumFeature.WRITE_ENUMS_TO_LOWERCASE.-
Fields inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer
_handledType
-
-
Constructor Summary
Constructors Constructor Description EnumSerializer(EnumValues v, java.lang.Boolean serializeAsIndex)Deprecated.Since 2.16EnumSerializer(EnumValues v, java.lang.Boolean serializeAsIndex, EnumValues valuesByEnumNaming)Deprecated.Since 2.16EnumSerializer(EnumValues v, java.lang.Boolean serializeAsIndex, EnumValues valuesByEnumNaming, EnumValues valuesByToString)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected static java.lang.Boolean_isShapeWrittenUsingIndex(java.lang.Class<?> enumClass, com.fasterxml.jackson.annotation.JsonFormat.Value format, boolean fromClass, java.lang.Boolean defaultValue)Helper method called to check whether serialization should be done using index (number) or not.protected boolean_serializeAsIndex(SerializerProvider serializers)voidacceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)Default implementation specifies no format.static EnumSerializerconstruct(java.lang.Class<?> enumClass, SerializationConfig config, BeanDescription beanDesc, com.fasterxml.jackson.annotation.JsonFormat.Value format)Factory method used byBasicSerializerFactoryfor constructing serializer instance of Enum types.protected static EnumValuesconstructEnumNamingStrategyValues(SerializationConfig config, java.lang.Class<java.lang.Enum<?>> enumClass, AnnotatedClass annotatedClass)Factory method used to resolve an instance ofEnumValueswithEnumNamingStrategyapplied for the target class.JsonSerializer<?>createContextual(SerializerProvider serializers, BeanProperty property)To support some level of per-property configuration, we will need to make things contextual.EnumValuesgetEnumValues()JsonNodegetSchema(SerializerProvider provider, java.lang.reflect.Type typeHint)Deprecated.Since 2.15voidserialize(java.lang.Enum<?> en, com.fasterxml.jackson.core.JsonGenerator gen, SerializerProvider serializers)Method that can be called to ask implementation to serialize values of type this serializer handles.-
Methods inherited from class com.fasterxml.jackson.databind.ser.std.StdScalarSerializer
serializeWithType
-
Methods inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer
_neitherNull, _nonEmpty, createSchemaNode, createSchemaNode, findAnnotatedContentSerializer, findContextualConvertingSerializer, findConvertingContentSerializer, findFormatFeature, findFormatOverrides, findIncludeOverrides, findPropertyFilter, getSchema, handledType, isDefaultSerializer, visitArrayFormat, visitArrayFormat, visitFloatFormat, visitIntFormat, visitIntFormat, visitStringFormat, visitStringFormat, wrapAndThrow, wrapAndThrow
-
Methods inherited from class com.fasterxml.jackson.databind.JsonSerializer
getDelegatee, isEmpty, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, unwrappingSerializer, usesObjectId, withFilterId, withIgnoredProperties
-
-
-
-
Field Detail
-
_values
protected final EnumValues _values
This map contains pre-resolved values (since there are ways to customize actual String constants to use) to use as serializations.
-
_serializeAsIndex
protected final java.lang.Boolean _serializeAsIndex
Flag that is set if we statically know serialization choice between index and textual format (null if it needs to be dynamically checked).- Since:
- 2.1
-
_valuesByEnumNaming
protected final EnumValues _valuesByEnumNaming
Map with key as converted property class defined implementation ofEnumNamingStrategyand with value as Enum names collected usingEnum.name().- Since:
- 2.15
-
_valuesByToString
protected final EnumValues _valuesByToString
Map that contains pre-resolved values forEnum.toString()to use for serialization, while respectingJsonPropertyandEnumFeature.WRITE_ENUMS_TO_LOWERCASE.- Since:
- 2.16
-
-
Constructor Detail
-
EnumSerializer
@Deprecated public EnumSerializer(EnumValues v, java.lang.Boolean serializeAsIndex)
Deprecated.Since 2.16
-
EnumSerializer
@Deprecated public EnumSerializer(EnumValues v, java.lang.Boolean serializeAsIndex, EnumValues valuesByEnumNaming)
Deprecated.Since 2.16- Since:
- 2.15
-
EnumSerializer
public EnumSerializer(EnumValues v, java.lang.Boolean serializeAsIndex, EnumValues valuesByEnumNaming, EnumValues valuesByToString)
- Since:
- 2.16
-
-
Method Detail
-
construct
public static EnumSerializer construct(java.lang.Class<?> enumClass, SerializationConfig config, BeanDescription beanDesc, com.fasterxml.jackson.annotation.JsonFormat.Value format)
Factory method used byBasicSerializerFactoryfor constructing serializer instance of Enum types.- Since:
- 2.1
-
createContextual
public JsonSerializer<?> createContextual(SerializerProvider serializers, BeanProperty property) throws JsonMappingException
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.- Specified by:
createContextualin interfaceContextualSerializer- Parameters:
serializers- Serializer provider to use for accessing config, other serializersproperty- Method or field that represents the property (and is used to access value to serialize). Should be available; but there may be cases where caller cannot provide it and null is passed instead (in which case impls usually pass 'this' serializer as is)- Returns:
- Serializer to use for serializing values of specified property; may be this instance or a new instance.
- Throws:
JsonMappingException
-
getEnumValues
public EnumValues getEnumValues()
-
serialize
public final void serialize(java.lang.Enum<?> en, com.fasterxml.jackson.core.JsonGenerator gen, SerializerProvider serializers) throws java.io.IOExceptionDescription copied from class:JsonSerializerMethod that can be called to ask implementation to serialize values of type this serializer handles.- Specified by:
serializein classStdSerializer<java.lang.Enum<?>>- Parameters:
en- Value to serialize; can not be null.gen- Generator used to output resulting Json contentserializers- Provider that can be used to get serializers for serializing Objects value contains, if any.- Throws:
java.io.IOException
-
getSchema
@Deprecated public JsonNode getSchema(SerializerProvider provider, java.lang.reflect.Type typeHint)
Deprecated.Since 2.15Description copied from class:StdSerializerDefault implementation simply claims type is "string"; usually overriden by custom serializers.- Specified by:
getSchemain interfaceSchemaAware- Overrides:
getSchemain classStdScalarSerializer<java.lang.Enum<?>>- Parameters:
provider- The serializer provider.typeHint- A hint about the type.- Returns:
- Json-schema for this serializer.
-
acceptJsonFormatVisitor
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException
Description copied from class:StdSerializerDefault implementation specifies no format. This behavior is usually overriden by custom serializers.- Specified by:
acceptJsonFormatVisitorin interfaceJsonFormatVisitable- Overrides:
acceptJsonFormatVisitorin classStdScalarSerializer<java.lang.Enum<?>>typeHint- Type of element (entity like property) being visited- Throws:
JsonMappingException
-
_serializeAsIndex
protected final boolean _serializeAsIndex(SerializerProvider serializers)
-
_isShapeWrittenUsingIndex
protected static java.lang.Boolean _isShapeWrittenUsingIndex(java.lang.Class<?> enumClass, com.fasterxml.jackson.annotation.JsonFormat.Value format, boolean fromClass, java.lang.Boolean defaultValue)Helper method called to check whether serialization should be done using index (number) or not.
-
constructEnumNamingStrategyValues
protected static EnumValues constructEnumNamingStrategyValues(SerializationConfig config, java.lang.Class<java.lang.Enum<?>> enumClass, AnnotatedClass annotatedClass)
Factory method used to resolve an instance ofEnumValueswithEnumNamingStrategyapplied for the target class.- Since:
- 2.15
-
-