Class CustomEnumDefinitionProvider

  • All Implemented Interfaces:
    CustomDefinitionProviderV2, StatefulConfig

    public class CustomEnumDefinitionProvider
    extends Object
    implements CustomDefinitionProviderV2
    Implementation of the CustomDefinitionProviderV2 interface for treating enum types as plain strings based on a JsonValue annotation being present with value = true on exactly one argument-free method and/or JsonProperty annotations being present on all enum constants. If no such annotations exist, no custom definition will be returned; thereby falling back on whatever is defined in a following custom definition (e.g. from one of the standard generator Options).
    • Constructor Detail

      • CustomEnumDefinitionProvider

        public CustomEnumDefinitionProvider​(boolean checkForJsonValueAnnotatedMethod,
                                            boolean checkForJsonPropertyAnnotations)
        Constructor indicating how to attempt to serialise enum constant values. If both flags are provided as true, the JsonValue annotated method will take precedence over JsonProperty annotations.
        Parameters:
        checkForJsonValueAnnotatedMethod - whether a single JsonValue annotated method should be invoked on each enum constant value
        checkForJsonPropertyAnnotations - whether each enum constant's JsonProperty annotation's value should be used
    • Method Detail

      • getSerializedValuesFromJsonValue

        protected List<Object> getSerializedValuesFromJsonValue​(com.fasterxml.classmate.ResolvedType javaType,
                                                                Object[] enumConstants,
                                                                SchemaGenerationContext context)
        Check whether the given type is an enum with at least one constant value and a single JsonValue annotated method with value = true and no expected arguments.
        Parameters:
        javaType - encountered type during schema generation
        enumConstants - non-empty array of enum constants
        context - current generation context
        Returns:
        results from invoking the JsonValue annotated method for each enum constant (or null if the criteria are not met)
      • getJsonValueAnnotatedMethod

        protected com.fasterxml.classmate.members.ResolvedMethod getJsonValueAnnotatedMethod​(com.fasterxml.classmate.ResolvedType javaType,
                                                                                             SchemaGenerationContext context)
        Look-up the single JsonValue annotated method with value = true and no expected arguments.
        Parameters:
        javaType - targeted type to look-up serialization method for
        context - generation context providing access to type resolution context
        Returns:
        single method with JsonValue annotation
      • getSerializedValuesFromJsonProperty

        protected List<String> getSerializedValuesFromJsonProperty​(com.fasterxml.classmate.ResolvedType javaType,
                                                                   Object[] enumConstants)
        Check whether the given type is an enum with at least one constant value and each enum constant value has a JsonProperty annotation.
        Parameters:
        javaType - encountered type during schema generation
        enumConstants - non-empty array of enum constants
        Returns:
        annotated JsonProperty.value() for each enum constant (or null if the criteria are not met)