public class EnumSerializer
extends StdScalarSerializer<java.lang.Enum<?>>
implements ContextualSerializer
Standard serializer used for
Enum
types.
Based on
StdScalarSerializer
since the JSON value is
scalar (String).
See Also:
Serialized Form
Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.
JsonSerializer
JsonSerializer.None
static
EnumSerializer
construct
(java.lang.Class<?> enumClass,
SerializationConfig
config,
BeanDescription
beanDesc,
JsonFormat.Value
format)
JsonSerializer
<?>
createContextual
(
SerializerProvider
serializers,
BeanProperty
property)
To support some level of per-property configuration, we will need
to make things contextual.
EnumValues
getEnumValues
()
JsonNode
getSchema
(
SerializerProvider
provider,
java.lang.reflect.Type typeHint)
Default implementation simply claims type is "string"; usually
overriden by custom serializers.
serialize
(java.lang.Enum<?> en,
JsonGenerator
gen,
SerializerProvider
serializers)
Method that can be called to ask implementation to serialize
values of type this serializer handles.
construct
public static EnumSerializer construct(java.lang.Class<?> enumClass,
SerializationConfig config,
BeanDescription beanDesc,
JsonFormat.Value format)
Since:
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:
createContextual
in interface
ContextualSerializer
Parameters:
serializers
- Serializer provider to use for accessing config, other serializers
property
- 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
public final void serialize(java.lang.Enum<?> en,
JsonGenerator gen,
SerializerProvider serializers)
throws java.io.IOException
Method that can be called to ask implementation to serialize
values of type this serializer handles.
Specified by:
serialize
in class
StdSerializer
<java.lang.Enum<?>>
Parameters:
en
- Value to serialize; can
not
be null.
gen
- Generator used to output resulting Json content
serializers
- Provider that can be used to get serializers for
serializing Objects value contains, if any.
Throws:
java.io.IOException
getSchema
public JsonNode getSchema(SerializerProvider provider,
java.lang.reflect.Type typeHint)
Default implementation simply claims type is "string"; usually
overriden by custom serializers.
Specified by:
getSchema
in interface
SchemaAware
Overrides:
getSchema
in class
StdScalarSerializer
<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
Default implementation specifies no format. This behavior is usually
overriden by custom serializers.
Specified by:
acceptJsonFormatVisitor
in interface
JsonFormatVisitable
Overrides:
acceptJsonFormatVisitor
in class
StdScalarSerializer
<java.lang.Enum<?>>
typeHint
- Type of element (entity like property) being visited
Throws:
JsonMappingException