## com.fasterxml.jackson.databind.ser.std
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<Enum<?>>
                  com.fasterxml.jackson.databind.ser.std.EnumSerializer

All Implemented Interfaces:
  JsonFormatVisitable, SchemaAware, ContextualSerializer

    public class EnumSerializer

extends StdScalarSerializer<Enum<?>>
implements ContextualSerializer

Standard serializer used for `Enum` types.

Based on `StdScalarSerializer` since the JSON value is scalar (String).

Author:
  tatu

Nested Class Summary

Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonSerializer
`JsonSerializer.None`

Field Summary
`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.

Fields inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer
`_handledType`

Constructor Summary
`EnumSerializer(EnumValues v)` Deprecated. Since 2.1
`EnumSerializer(EnumValues v, Boolean serializeAsIndex)`

Method Summary
`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)` Deprecated. Since 2.1 use the variant that takes in `format` argument.
`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.

Methods inherited from class com.fasterxml.jackson.databind.ser.std.StdScalarSerializer
`serializeWithType`

Methods inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer
`createObjectNode, createSchemaNode, createSchemaNode, getSchema, handledType, isDefaultSerializer, wrapAndThrow, wrapAndThrow`

Methods inherited from class com.fasterxml.jackson.databind.JsonSerializer
`getDelegatee, isEmpty, isUnwrappingSerializer, replaceDelegatee, unwrappingSerializer, usesObjectId`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

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 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

Constructor Detail

### EnumSerializer

    @Deprecated
    public EnumSerializer(EnumValues v)

  Deprecated. Since 2.1

### EnumSerializer

    public EnumSerializer(EnumValues v,
                          Boolean serializeAsIndex)

Method Detail

### construct

    public 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.

  Since:
    2.1

### construct

    @Deprecated
    public static EnumSerializer construct(Class<Enum<?>> enumClass,
                                                      SerializationConfig config,
                                                      BeanDescription beanDesc)

  Deprecated. Since 2.1 use the variant that takes in `format` argument.

### createContextual

    public JsonSerializer<?> createContextual(SerializerProvider prov,
                                              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:
    `prov` - 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 can not 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(Enum<?> en,
                                JsonGenerator jgen,
                                SerializerProvider provider)
                         throws IOException,
                                JsonGenerationException

  Description copied from class: `JsonSerializer`
  Method that can be called to ask implementation to serialize values of type this serializer handles.

  Specified by:
    `serialize` in class `StdSerializer<Enum<?>>`
  Parameters:
    `en` - Value to serialize; can not be null.
    `jgen` - Generator used to output resulting Json content
    `provider` - Provider that can be used to get serializers for serializing Objects value contains, if any.
  Throws:
    `IOException`
    `JsonGenerationException`

### getSchema

    public JsonNode getSchema(SerializerProvider provider,
                              Type typeHint)

  Description copied from class: `StdSerializer`
  Default implementation simply claims type is "string"; usually overriden by custom serializers.

  Specified by:
    `getSchema` in interface `SchemaAware`
  Overrides:
    `getSchema` in class `StdScalarSerializer<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)

  Description copied from class: `StdSerializer`
  Default implementation specifies no format. This behavior is usually overriden by custom serializers.

  Specified by:
    `acceptJsonFormatVisitor` in interface `JsonFormatVisitable`
  Overrides:
    `acceptJsonFormatVisitor` in class `StdScalarSerializer<Enum<?>>`
    `typeHint` - Type of element (entity like property) being visited

### _serializeAsIndex

    protected final boolean _serializeAsIndex(SerializerProvider provider)

### _isShapeWrittenUsingIndex

    protected static Boolean _isShapeWrittenUsingIndex(Class<?> enumClass,
                                                       JsonFormat.Value format,
                                                       boolean fromClass)

  Helper method called to check whether

Copyright © 2012 FasterXML. All Rights Reserved.