Class EnumSerializer
java.lang.Object
com.fasterxml.jackson.databind.JsonSerializer<Enum<?>>
com.fasterxml.jackson.databind.ser.std.StdSerializer<Enum<?>>
com.fasterxml.jackson.databind.ser.std.StdScalarSerializer<Enum<?>>
com.fasterxml.jackson.databind.ser.std.EnumSerializer
- All Implemented Interfaces:
JsonFormatVisitable,SchemaAware,ContextualSerializer,Serializable
Standard serializer used for
Enum types.
Based on StdScalarSerializer since the JSON value is
scalar (String).
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonSerializer
JsonSerializer.None -
Constructor Summary
ConstructorsConstructorDescriptionEnumSerializer(EnumValues v, Boolean serializeAsIndex) Deprecated.Since 2.16EnumSerializer(EnumValues v, Boolean serializeAsIndex, EnumValues valuesByEnumNaming) Deprecated.Since 2.16EnumSerializer(EnumValues v, Boolean serializeAsIndex, EnumValues valuesByEnumNaming, EnumValues valuesByToString) -
Method Summary
Modifier and TypeMethodDescriptionvoidacceptJsonFormatVisitor(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(SerializerProvider serializers, BeanProperty property) To support some level of per-property configuration, we will need to make things contextual.getSchema(SerializerProvider provider, Type typeHint) Deprecated.Since 2.15final voidserialize(Enum<?> en, 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
serializeWithTypeMethods inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer
getSchema, handledType, wrapAndThrow, wrapAndThrowMethods inherited from class com.fasterxml.jackson.databind.JsonSerializer
getDelegatee, isEmpty, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, unwrappingSerializer, usesObjectId, withFilterId, withIgnoredProperties
-
Constructor Details
-
EnumSerializer
Deprecated.Since 2.16 -
EnumSerializer
@Deprecated public EnumSerializer(EnumValues v, Boolean serializeAsIndex, EnumValues valuesByEnumNaming) Deprecated.Since 2.16- Since:
- 2.15
-
EnumSerializer
public EnumSerializer(EnumValues v, Boolean serializeAsIndex, EnumValues valuesByEnumNaming, EnumValues valuesByToString) - Since:
- 2.16
-
-
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.- 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
-
serialize
public final void serialize(Enum<?> en, JsonGenerator gen, SerializerProvider serializers) throws IOException Description copied from class:JsonSerializerMethod 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.gen- Generator used to output resulting Json contentserializers- Provider that can be used to get serializers for serializing Objects value contains, if any.- Throws:
IOException
-
getSchema
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<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<Enum<?>>- Parameters:
typeHint- Type of element (entity like property) being visited- Throws:
JsonMappingException
-