com.fasterxml.jackson.databind.ser.std

Class EnumSerializer

    • 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

    • Method Detail

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

        public EnumValues getEnumValues()
      • serialize

        public final void serialize(Enum<?> en,
                                    com.fasterxml.jackson.core.JsonGenerator gen,
                                    SerializerProvider serializers)
                             throws IOException
        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.
        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:
        IOException
      • _serializeAsIndex

        protected final boolean _serializeAsIndex(SerializerProvider serializers)
      • _isShapeWrittenUsingIndex

        protected static Boolean _isShapeWrittenUsingIndex(Class<?> enumClass,
                                                           com.fasterxml.jackson.annotation.JsonFormat.Value format,
                                                           boolean fromClass,
                                                           Boolean defaultValue)
        Helper method called to check whether serialization should be done using index (number) or not.

Copyright © 2008–2023 FasterXML. All rights reserved.