Class CustomEnumDefinitionProvider

java.lang.Object
com.github.victools.jsonschema.module.jackson.CustomEnumDefinitionProvider
All Implemented Interfaces:
com.github.victools.jsonschema.generator.CustomDefinitionProviderV2, com.github.victools.jsonschema.generator.StatefulConfig

public class CustomEnumDefinitionProvider extends Object implements com.github.victools.jsonschema.generator.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 Summary

    Constructors
    Constructor
    Description
    CustomEnumDefinitionProvider(boolean checkForJsonValueAnnotatedMethod, boolean checkForJsonPropertyAnnotations)
    Constructor indicating how to attempt to serialise enum constant values.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected com.fasterxml.classmate.members.ResolvedMethod
    getJsonValueAnnotatedMethod(com.fasterxml.classmate.ResolvedType javaType, com.github.victools.jsonschema.generator.SchemaGenerationContext context)
    Look-up the single JsonValue annotated method with value = true and no expected arguments.
    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.
    protected List<Object>
    getSerializedValuesFromJsonValue(com.fasterxml.classmate.ResolvedType javaType, Object[] enumConstants, com.github.victools.jsonschema.generator.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.
    com.github.victools.jsonschema.generator.CustomDefinition
    provideCustomSchemaDefinition(com.fasterxml.classmate.ResolvedType javaType, com.github.victools.jsonschema.generator.SchemaGenerationContext context)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.github.victools.jsonschema.generator.StatefulConfig

    resetAfterSchemaGenerationFinished
  • Constructor Details

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

    • provideCustomSchemaDefinition

      public com.github.victools.jsonschema.generator.CustomDefinition provideCustomSchemaDefinition(com.fasterxml.classmate.ResolvedType javaType, com.github.victools.jsonschema.generator.SchemaGenerationContext context)
      Specified by:
      provideCustomSchemaDefinition in interface com.github.victools.jsonschema.generator.CustomDefinitionProviderV2
    • getSerializedValuesFromJsonValue

      protected List<Object> getSerializedValuesFromJsonValue(com.fasterxml.classmate.ResolvedType javaType, Object[] enumConstants, com.github.victools.jsonschema.generator.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, com.github.victools.jsonschema.generator.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)