Class CustomEnumDefinitionProvider
- java.lang.Object
-
- com.github.victools.jsonschema.module.jackson.CustomEnumDefinitionProvider
-
- All Implemented Interfaces:
CustomDefinitionProviderV2
,StatefulConfig
public class CustomEnumDefinitionProvider extends Object implements CustomDefinitionProviderV2
Implementation of theCustomDefinitionProviderV2
interface for treating enum types as plain strings based on aJsonValue
annotation being present withvalue = true
on exactly one argument-free method and/orJsonProperty
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 generatorOption
s).
-
-
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.ResolvedMethod
getJsonValueAnnotatedMethod(com.fasterxml.classmate.ResolvedType javaType, SchemaGenerationContext context)
Look-up the singleJsonValue
annotated method withvalue = 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 aJsonProperty
annotation.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 singleJsonValue
annotated method withvalue = true
and no expected arguments.CustomDefinition
provideCustomSchemaDefinition(com.fasterxml.classmate.ResolvedType javaType, 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 Detail
-
CustomEnumDefinitionProvider
public CustomEnumDefinitionProvider(boolean checkForJsonValueAnnotatedMethod, boolean checkForJsonPropertyAnnotations)
Constructor indicating how to attempt to serialise enum constant values. If both flags are provided astrue
, theJsonValue
annotated method will take precedence overJsonProperty
annotations.- Parameters:
checkForJsonValueAnnotatedMethod
- whether a singleJsonValue
annotated method should be invoked on each enum constant valuecheckForJsonPropertyAnnotations
- whether each enum constant'sJsonProperty
annotation'svalue
should be used
-
-
Method Detail
-
provideCustomSchemaDefinition
public CustomDefinition provideCustomSchemaDefinition(com.fasterxml.classmate.ResolvedType javaType, SchemaGenerationContext context)
- Specified by:
provideCustomSchemaDefinition
in 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 singleJsonValue
annotated method withvalue = true
and no expected arguments.- Parameters:
javaType
- encountered type during schema generationenumConstants
- non-empty array of enum constantscontext
- current generation context- Returns:
- results from invoking the
JsonValue
annotated method for each enum constant (ornull
if the criteria are not met)
-
getJsonValueAnnotatedMethod
protected com.fasterxml.classmate.members.ResolvedMethod getJsonValueAnnotatedMethod(com.fasterxml.classmate.ResolvedType javaType, SchemaGenerationContext context)
Look-up the singleJsonValue
annotated method withvalue = true
and 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
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 aJsonProperty
annotation.- Parameters:
javaType
- encountered type during schema generationenumConstants
- non-empty array of enum constants- Returns:
- annotated
JsonProperty.value()
for each enum constant (ornull
if the criteria are not met)
-
-