public class EnumSerializer extends StdScalarSerializer<Enum<?>> implements ContextualSerializer
Enum
types.
Based on StdScalarSerializer
since the JSON value is
scalar (String).
JsonSerializer.None
Modifier and Type | Field and Description |
---|---|
protected 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).
|
protected EnumValues |
_values
This map contains pre-resolved values (since there are ways
to customize actual String constants to use) to use as
serializations.
|
_handledType
Constructor and Description |
---|
EnumSerializer(EnumValues v)
Deprecated.
Since 2.1
|
EnumSerializer(EnumValues v,
Boolean serializeAsIndex) |
Modifier and Type | Method and Description |
---|---|
protected static Boolean |
_isShapeWrittenUsingIndex(Class<?> enumClass,
JsonFormat.Value format,
boolean fromClass)
Helper method called to check whether
|
protected boolean |
_serializeAsIndex(SerializerProvider provider) |
void |
acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor,
JavaType typeHint)
Default implementation specifies no format.
|
static EnumSerializer |
construct(Class<Enum<?>> enumClass,
SerializationConfig config,
BeanDescription beanDesc,
JsonFormat.Value format)
Factory method used by
BasicSerializerFactory
for constructing serializer instance of Enum types. |
JsonSerializer<?> |
createContextual(SerializerProvider prov,
BeanProperty property)
To support some level of per-property configuration, we will need
to make things contextual.
|
EnumValues |
getEnumValues() |
JsonNode |
getSchema(SerializerProvider provider,
Type typeHint)
Default implementation simply claims type is "string"; usually
overriden by custom serializers.
|
void |
serialize(Enum<?> en,
JsonGenerator jgen,
SerializerProvider provider)
Method that can be called to ask implementation to serialize
values of type this serializer handles.
|
serializeWithType
createObjectNode, createSchemaNode, createSchemaNode, findConvertingContentSerializer, findPropertyFilter, getSchema, handledType, isDefaultSerializer, wrapAndThrow, wrapAndThrow
getDelegatee, isEmpty, isUnwrappingSerializer, replaceDelegatee, unwrappingSerializer, usesObjectId
protected final EnumValues _values
protected final Boolean _serializeAsIndex
@Deprecated public EnumSerializer(EnumValues v)
public EnumSerializer(EnumValues v, Boolean serializeAsIndex)
public static EnumSerializer construct(Class<Enum<?>> enumClass, SerializationConfig config, BeanDescription beanDesc, JsonFormat.Value format)
BasicSerializerFactory
for constructing serializer instance of Enum types.public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException
createContextual
in interface ContextualSerializer
prov
- 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 can not provide it and
null is passed instead (in which case impls usually pass 'this' serializer as is)JsonMappingException
public EnumValues getEnumValues()
public final void serialize(Enum<?> en, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException
JsonSerializer
serialize
in class StdSerializer<Enum<?>>
en
- Value to serialize; can not be null.jgen
- Generator used to output resulting Json contentprovider
- Provider that can be used to get serializers for
serializing Objects value contains, if any.IOException
JsonGenerationException
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
StdSerializer
getSchema
in interface SchemaAware
getSchema
in class StdScalarSerializer<Enum<?>>
provider
- The serializer provider.typeHint
- A hint about the type.public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException
StdSerializer
acceptJsonFormatVisitor
in interface JsonFormatVisitable
acceptJsonFormatVisitor
in class StdScalarSerializer<Enum<?>>
typeHint
- Type of element (entity like property) being visitedJsonMappingException
protected final boolean _serializeAsIndex(SerializerProvider provider)
protected static Boolean _isShapeWrittenUsingIndex(Class<?> enumClass, JsonFormat.Value format, boolean fromClass)
Copyright © 2014-2015 FasterXML. All Rights Reserved.