Class JacksonSchemaModule
java.lang.Object
com.github.victools.jsonschema.module.jackson.JacksonSchemaModule
- All Implemented Interfaces:
com.github.victools.jsonschema.generator.Module
- Direct Known Subclasses:
JacksonModule
public class JacksonSchemaModule
extends Object
implements com.github.victools.jsonschema.generator.Module
Module for setting up schema generation aspects based on
jackson-annotations.
- Populate the "description" attributes as per
JsonPropertyDescriptionandJsonClassDescriptionannotations. - Apply alternative property names defined in
JsonPropertyannotations. - Exclude properties that are deemed to be ignored per the various annotations for that purpose.
- Optionally: treat enum types as plain strings as per
JsonValueannotations.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor, without any additional options.JacksonSchemaModule(JacksonOption... options) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyToConfigBuilder(com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder builder) protected final tools.jackson.databind.BeanDescriptiongetBeanDescriptionForClass(com.fasterxml.classmate.ResolvedType targetType) Create a jacksonBeanDescriptionfor the given type's erased class in order to avoid having to re-create the complexity therein.protected StringgetPropertyNameOverrideBasedOnJsonNamingAnnotation(com.github.victools.jsonschema.generator.FieldScope field) Alter the declaring name of the given field as per the declaring type'sJsonNamingannotation.protected StringgetPropertyNameOverrideBasedOnJsonPropertyAnnotation(com.github.victools.jsonschema.generator.MemberScope<?, ?> member) Look-up an alternative name as per the following order of priority.protected booleangetReadOnlyCheck(com.github.victools.jsonschema.generator.MemberScope<?, ?> member) Determine whether the given field's/method'sJsonPropertyannotation marks it as read-only.protected booleangetRequiredCheckBasedOnJsonPropertyAnnotation(com.github.victools.jsonschema.generator.MemberScope<?, ?> member) Look-up the given field's/method'sJsonPropertyannotation and consider its "required" attribute.protected booleangetWriteOnlyCheck(com.github.victools.jsonschema.generator.MemberScope<?, ?> member) Determine whether the given field's/method'sJsonPropertyannotation marks it as write-only.protected StringresolveDescription(com.github.victools.jsonschema.generator.MemberScope<?, ?> member) Determine the given member's associated "description" in the following order of priority.protected StringresolveDescriptionForType(com.github.victools.jsonschema.generator.TypeScope scope) Determine the given type's associated "description" via the following annotation.protected booleanshouldIgnoreField(com.github.victools.jsonschema.generator.FieldScope field) Determine whether a given field should be ignored, according to various jackson annotations for that purpose,
e.g.protected booleanshouldIgnoreMethod(com.github.victools.jsonschema.generator.MethodScope method) Determine whether a given method should be ignored, according to various jackson annotations for that purpose,
e.g.
-
Constructor Details
-
JacksonSchemaModule
public JacksonSchemaModule()Constructor, without any additional options.- See Also:
-
JacksonSchemaModule
Constructor.- Parameters:
options- features to enable
-
-
Method Details
-
applyToConfigBuilder
public void applyToConfigBuilder(com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder builder) - Specified by:
applyToConfigBuilderin interfacecom.github.victools.jsonschema.generator.Module
-
resolveDescription
protected String resolveDescription(com.github.victools.jsonschema.generator.MemberScope<?, ?> member) Determine the given member's associated "description" in the following order of priority.JsonPropertyDescriptionannotation on the field/method itselfJsonPropertyDescriptionannotation on the field's getter method or the getter method's associated field
- Parameters:
member- field/method for which to collect an available description- Returns:
- successfully looked-up description (or
null)
-
resolveDescriptionForType
protected String resolveDescriptionForType(com.github.victools.jsonschema.generator.TypeScope scope) Determine the given type's associated "description" via the following annotation.JsonClassDescriptionannotation on the targeted type's class
- Parameters:
scope- scope for which to collect an available description- Returns:
- successfully looked-up description (or
null)
-
getPropertyNameOverrideBasedOnJsonPropertyAnnotation
protected String getPropertyNameOverrideBasedOnJsonPropertyAnnotation(com.github.victools.jsonschema.generator.MemberScope<?, ?> member) Look-up an alternative name as per the following order of priority.JsonPropertyannotation on the member itselfJsonPropertyannotation on the field's getter method or the getter method's associated field
- Parameters:
member- field/method to look-up alternative property name for- Returns:
- alternative property name (or
null)
-
getPropertyNameOverrideBasedOnJsonNamingAnnotation
protected String getPropertyNameOverrideBasedOnJsonNamingAnnotation(com.github.victools.jsonschema.generator.FieldScope field) Alter the declaring name of the given field as per the declaring type'sJsonNamingannotation.- Parameters:
field- field to look-up naming strategy for- Returns:
- altered property name (or
null)
-
getBeanDescriptionForClass
protected final tools.jackson.databind.BeanDescription getBeanDescriptionForClass(com.fasterxml.classmate.ResolvedType targetType) Create a jacksonBeanDescriptionfor the given type's erased class in order to avoid having to re-create the complexity therein.
This is assumed to have a negative performance impact (as one type is being introspected twice), that should be fine for schema generation.- Parameters:
targetType- type for whose erased class theBeanDescriptionshould be created- Returns:
- introspection result of given type's erased class
-
shouldIgnoreField
protected boolean shouldIgnoreField(com.github.victools.jsonschema.generator.FieldScope field) Determine whether a given field should be ignored, according to various jackson annotations for that purpose,
e.g.JsonBackReference,JsonIgnore,JsonIgnoreType,JsonIgnoreProperties- Parameters:
field- field to check- Returns:
- whether field should be excluded
-
shouldIgnoreMethod
protected boolean shouldIgnoreMethod(com.github.victools.jsonschema.generator.MethodScope method) Determine whether a given method should be ignored, according to various jackson annotations for that purpose,
e.g.JsonBackReference,JsonIgnore,JsonIgnoreType,JsonIgnoreProperties- Parameters:
method- method to check- Returns:
- whether method should be excluded
-
getRequiredCheckBasedOnJsonPropertyAnnotation
protected boolean getRequiredCheckBasedOnJsonPropertyAnnotation(com.github.victools.jsonschema.generator.MemberScope<?, ?> member) Look-up the given field's/method'sJsonPropertyannotation and consider its "required" attribute.- Parameters:
member- field/method to look-up required strategy for- Returns:
- whether the field should be in the "required" list or not
-
getReadOnlyCheck
protected boolean getReadOnlyCheck(com.github.victools.jsonschema.generator.MemberScope<?, ?> member) Determine whether the given field's/method'sJsonPropertyannotation marks it as read-only.- Parameters:
member- field/method to check read-only status for- Returns:
- whether the field should be marked as read-only
-
getWriteOnlyCheck
protected boolean getWriteOnlyCheck(com.github.victools.jsonschema.generator.MemberScope<?, ?> member) Determine whether the given field's/method'sJsonPropertyannotation marks it as write-only.- Parameters:
member- field/method to check write-only status for- Returns:
- whether the field should be marked as write-only
-