Class JacksonModule
- java.lang.Object
-
- com.github.victools.jsonschema.module.jackson.JacksonModule
-
- All Implemented Interfaces:
Module
public class JacksonModule extends Object implements Module
Module for setting up schema generation aspects based onjackson-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
Constructors Constructor Description JacksonModule()Constructor, without any additional options.JacksonModule(JacksonOption... options)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyToConfigBuilder(SchemaGeneratorConfigBuilder builder)protected com.fasterxml.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(FieldScope field)Alter the declaring name of the given field as per the declaring type'sJsonNamingannotation.protected StringgetPropertyNameOverrideBasedOnJsonPropertyAnnotation(MemberScope<?,?> member)Look-up an alternative name as per the following order of priority.protected booleangetReadOnlyCheck(MemberScope<?,?> member)Determine whether the given field's/method'sJsonPropertyannotation marks it as read-only.protected booleangetRequiredCheckBasedOnJsonPropertyAnnotation(MemberScope<?,?> member)Look-up the given field's/method'sJsonPropertyannotation and consider its "required" attribute.protected booleangetWriteOnlyCheck(MemberScope<?,?> member)Determine whether the given field's/method'sJsonPropertyannotation marks it as write-only.protected StringresolveDescription(MemberScope<?,?> member)Determine the given member's associated "description" in the following order of priority.protected StringresolveDescriptionForType(TypeScope scope)Determine the given type's associated "description" via the following annotation.protected booleanshouldIgnoreField(FieldScope field)Determine whether a given field should be ignored, according to various jackson annotations for that purpose,
e.g.protected booleanshouldIgnoreMethod(MethodScope method)Determine whether a given method should be ignored, according to various jackson annotations for that purpose,
e.g.
-
-
-
Constructor Detail
-
JacksonModule
public JacksonModule()
Constructor, without any additional options.- See Also:
JacksonModule(JacksonOption...)
-
JacksonModule
public JacksonModule(JacksonOption... options)
Constructor.- Parameters:
options- features to enable
-
-
Method Detail
-
applyToConfigBuilder
public void applyToConfigBuilder(SchemaGeneratorConfigBuilder builder)
- Specified by:
applyToConfigBuilderin interfaceModule
-
resolveDescription
protected String resolveDescription(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(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(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(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 com.fasterxml.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(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(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(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(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(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
-
-