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
ConstructorsConstructorDescriptionCustomEnumDefinitionProvider(boolean checkForJsonValueAnnotatedMethod, boolean checkForJsonPropertyAnnotations) Constructor indicating how to attempt to serialise enum constant values. -
Method Summary
Modifier and TypeMethodDescriptionprotected com.fasterxml.classmate.members.ResolvedMethodgetJsonValueAnnotatedMethod(com.fasterxml.classmate.ResolvedType javaType, com.github.victools.jsonschema.generator.SchemaGenerationContext context) Look-up the singleJsonValueannotated method withvalue = trueand no expected arguments.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 aJsonPropertyannotation.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 singleJsonValueannotated method withvalue = trueand no expected arguments.com.github.victools.jsonschema.generator.CustomDefinitionprovideCustomSchemaDefinition(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, waitMethods 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 astrue, theJsonValueannotated method will take precedence overJsonPropertyannotations.- Parameters:
checkForJsonValueAnnotatedMethod- whether a singleJsonValueannotated method should be invoked on each enum constant valuecheckForJsonPropertyAnnotations- whether each enum constant'sJsonPropertyannotation'svalueshould 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:
provideCustomSchemaDefinitionin interfacecom.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 singleJsonValueannotated method withvalue = trueand no expected arguments.- Parameters:
javaType- encountered type during schema generationenumConstants- non-empty array of enum constantscontext- current generation context- Returns:
- results from invoking the
JsonValueannotated method for each enum constant (ornullif 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 singleJsonValueannotated method withvalue = trueand no expected arguments.- Parameters:
javaType- targeted type to look-up serialization method forcontext- generation context providing access to type resolution context- Returns:
- single method with
JsonValueannotation
-
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 aJsonPropertyannotation.- Parameters:
javaType- encountered type during schema generationenumConstants- non-empty array of enum constants- Returns:
- annotated
JsonProperty.value()for each enum constant (ornullif the criteria are not met)
-