Class EnumResolver

  • All Implemented Interfaces:
    java.io.Serializable

    public class EnumResolver
    extends java.lang.Object
    implements java.io.Serializable
    Helper class used to resolve String values (either JSON Object field names or regular String values) into Java Enum instances.
    See Also:
    Serialized Form
    • Field Detail

      • _enumClass

        protected final java.lang.Class<java.lang.Enum<?>> _enumClass
      • _enums

        protected final java.lang.Enum<?>[] _enums
      • _enumsById

        protected final java.util.HashMap<java.lang.String,​java.lang.Enum<?>> _enumsById
      • _defaultValue

        protected final java.lang.Enum<?> _defaultValue
      • _isIgnoreCase

        protected final boolean _isIgnoreCase
        Marker for case-insensitive handling
        Since:
        2.12
      • _isFromIntValue

        protected final boolean _isFromIntValue
        Marker for case where value may come from @JsonValue annotated accessor and is expected/likely to come from actual integral number value (and not String).

        Special case is needed since this specifically means that Enum.index() should NOT be used or default to.

        Since:
        2.13
      • _hasAsValueAnnotation

        protected final boolean _hasAsValueAnnotation
        Marker for case where enum values to match are from @JsonValue-annotated method.
        Since:
        2.20
    • Constructor Detail

      • EnumResolver

        protected EnumResolver​(java.lang.Class<java.lang.Enum<?>> enumClass,
                               java.lang.Enum<?>[] enums,
                               java.util.HashMap<java.lang.String,​java.lang.Enum<?>> map,
                               java.lang.Enum<?> defaultValue,
                               boolean isIgnoreCase,
                               boolean isFromIntValue,
                               boolean hasAsValueAnnotation)
        Since:
        2.20
      • EnumResolver

        @Deprecated
        protected EnumResolver​(java.lang.Class<java.lang.Enum<?>> enumClass,
                               java.lang.Enum<?>[] enums,
                               java.util.HashMap<java.lang.String,​java.lang.Enum<?>> map,
                               java.lang.Enum<?> defaultValue,
                               boolean isIgnoreCase,
                               boolean isFromIntValue)
        Deprecated.
        Since 2.20; use variant that also takes hasAsValueAnnotation argument
        Since:
        2.12
    • Method Detail

      • constructUsingToString

        public static EnumResolver constructUsingToString​(DeserializationConfig config,
                                                          AnnotatedClass annotatedClass)
        Factory method for constructing resolver that maps from Enum.toString() into Enum value
        Since:
        2.16
      • constructUsingIndex

        public static EnumResolver constructUsingIndex​(DeserializationConfig config,
                                                       AnnotatedClass annotatedClass)
        Factory method for constructing resolver that maps from index of Enum.values() into Enum value.
        Since:
        2.16
      • _enumClass

        protected static java.lang.Class<java.lang.Enum<?>> _enumClass​(java.lang.Class<?> enumCls0)
      • _enumConstants

        protected static java.lang.Enum<?>[] _enumConstants​(java.lang.Class<?> enumCls)
      • _isIntType

        protected static boolean _isIntType​(java.lang.Class<?> erasedType)
      • findEnum

        public java.lang.Enum<?> findEnum​(java.lang.String key)
      • _findEnumCaseInsensitive

        protected java.lang.Enum<?> _findEnumCaseInsensitive​(java.lang.String key)
      • getEnum

        public java.lang.Enum<?> getEnum​(int index)
      • getDefaultValue

        public java.lang.Enum<?> getDefaultValue()
      • getRawEnums

        public java.lang.Enum<?>[] getRawEnums()
      • getEnums

        public java.util.List<java.lang.Enum<?>> getEnums()
      • getEnumIds

        public java.util.Collection<java.lang.String> getEnumIds()
        Since:
        2.7.3
      • getEnumClass

        public java.lang.Class<java.lang.Enum<?>> getEnumClass()
      • lastValidIndex

        public int lastValidIndex()
      • isFromIntValue

        public boolean isFromIntValue()
        Accessor for checking if we have a special case in which value to map is from @JsonValue annotated accessor with integral type: this matters for cases where incoming content value is of integral type and should be mapped to specific value and NOT to Enum.index().
        Since:
        2.13
      • hasAsValueAnnotation

        public boolean hasAsValueAnnotation()
        Accessor for checking whether @JsonValue annotated accessor is used to get enum values to use for deserialization.
        Since:
        2.20