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,
Boolean serializeAsIndex) |
Modifier and Type | Method and Description |
---|---|
protected static Boolean |
_isShapeWrittenUsingIndex(Class<?> enumClass,
JsonFormat.Value format,
boolean fromClass,
Boolean defaultValue)
Helper method called to check whether serialization should be done using
index (number) or not.
|
protected boolean |
_serializeAsIndex(SerializerProvider serializers) |
void |
acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor,
JavaType typeHint)
Default implementation specifies no format.
|
static EnumSerializer |
construct(Class<?> enumClass,
SerializationConfig config,
BeanDescription beanDesc,
JsonFormat.Value format)
Factory method used by
BasicSerializerFactory
for constructing serializer instance of Enum types. |
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,
Type typeHint)
Default implementation simply claims type is "string"; usually
overriden by custom serializers.
|
void |
serialize(Enum<?> en,
JsonGenerator gen,
SerializerProvider serializers)
Method that can be called to ask implementation to serialize
values of type this serializer handles.
|
serializeWithType
_neitherNull, _nonEmpty, createSchemaNode, createSchemaNode, findAnnotatedContentSerializer, findContextualConvertingSerializer, findConvertingContentSerializer, findFormatFeature, findFormatOverrides, findIncludeOverrides, findPropertyFilter, getSchema, handledType, isDefaultSerializer, visitArrayFormat, visitArrayFormat, visitFloatFormat, visitIntFormat, visitIntFormat, visitStringFormat, visitStringFormat, wrapAndThrow, wrapAndThrow
getDelegatee, isEmpty, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, unwrappingSerializer, usesObjectId, withFilterId
protected final EnumValues _values
protected final Boolean _serializeAsIndex
public EnumSerializer(EnumValues v, Boolean serializeAsIndex)
public static EnumSerializer construct(Class<?> enumClass, SerializationConfig config, BeanDescription beanDesc, JsonFormat.Value format)
BasicSerializerFactory
for constructing serializer instance of Enum types.public JsonSerializer<?> createContextual(SerializerProvider serializers, BeanProperty property) throws JsonMappingException
createContextual
in interface ContextualSerializer
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)JsonMappingException
public EnumValues getEnumValues()
public final void serialize(Enum<?> en, JsonGenerator gen, SerializerProvider serializers) throws IOException
JsonSerializer
serialize
in class StdSerializer<Enum<?>>
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.IOException
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 serializers)
protected static Boolean _isShapeWrittenUsingIndex(Class<?> enumClass, JsonFormat.Value format, boolean fromClass, Boolean defaultValue)
Copyright © 2021 JBoss by Red Hat. All rights reserved.