Class CustomEnumDefinitionProvider
- java.lang.Object
-
- com.github.victools.jsonschema.module.jackson.CustomEnumDefinitionProvider
-
- All Implemented Interfaces:
CustomDefinitionProviderV2
public class CustomEnumDefinitionProvider extends Object implements CustomDefinitionProviderV2
Implementation of theCustomDefinitionProviderV2interface for treating enum types as plain strings based on aJsonValueannotation being present withvalue = trueon exactly one argument-free method and/orJsonPropertyannotations 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 generatorOptions).
-
-
Constructor Summary
Constructors Constructor Description CustomEnumDefinitionProvider(boolean checkForJsonValueAnnotatedMethod, boolean checkForJsonPropertyAnnotations)Constructor indicating how to attempt to serialise enum constant values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected com.fasterxml.classmate.members.ResolvedMethodgetJsonValueAnnotatedMethod(com.fasterxml.classmate.ResolvedType javaType, SchemaGenerationContext context)Look-up the singleJsonValueannotated method withvalue = trueand 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 aJsonPropertyannotation.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 singleJsonValueannotated method withvalue = trueand no expected arguments.CustomDefinitionprovideCustomSchemaDefinition(com.fasterxml.classmate.ResolvedType javaType, SchemaGenerationContext context)
-
-
-
Constructor Detail
-
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 Detail
-
provideCustomSchemaDefinition
public CustomDefinition provideCustomSchemaDefinition(com.fasterxml.classmate.ResolvedType javaType, SchemaGenerationContext context)
- Specified by:
provideCustomSchemaDefinitionin interfaceCustomDefinitionProviderV2
-
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 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, 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)
-
-