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
JsonPropertyDescription
andJsonClassDescription
annotations. - Apply alternative property names defined in
JsonProperty
annotations. - Exclude properties that are deemed to be ignored per the various annotations for that purpose.
- Optionally: treat enum types as plain strings as per
JsonValue
annotations.
-
-
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 void
applyToConfigBuilder(SchemaGeneratorConfigBuilder builder)
protected com.fasterxml.jackson.databind.BeanDescription
getBeanDescriptionForClass(com.fasterxml.classmate.ResolvedType targetType)
Create a jacksonBeanDescription
for the given type's erased class in order to avoid having to re-create the complexity therein.protected String
getPropertyNameOverrideBasedOnJsonNamingAnnotation(FieldScope field)
Alter the declaring name of the given field as per the declaring type'sJsonNaming
annotation.protected String
getPropertyNameOverrideBasedOnJsonPropertyAnnotation(MemberScope<?,?> member)
Look-up an alternative name as per the following order of priority.protected boolean
getReadOnlyCheck(MemberScope<?,?> member)
Determine whether the given field's/method'sJsonProperty
annotation marks it as read-only.protected boolean
getRequiredCheckBasedOnJsonPropertyAnnotation(MemberScope<?,?> member)
Look-up the given field's/method'sJsonProperty
annotation and consider its "required" attribute.protected boolean
getWriteOnlyCheck(MemberScope<?,?> member)
Determine whether the given field's/method'sJsonProperty
annotation marks it as write-only.protected String
resolveDescription(MemberScope<?,?> member)
Determine the given member's associated "description" in the following order of priority.protected String
resolveDescriptionForType(TypeScope scope)
Determine the given type's associated "description" via the following annotation.protected boolean
shouldIgnoreField(FieldScope field)
Determine whether a given field should be ignored, according to various jackson annotations for that purpose,
e.g.protected boolean
shouldIgnoreMethod(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:
applyToConfigBuilder
in interfaceModule
-
resolveDescription
protected String resolveDescription(MemberScope<?,?> member)
Determine the given member's associated "description" in the following order of priority.JsonPropertyDescription
annotation on the field/method itselfJsonPropertyDescription
annotation 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.JsonClassDescription
annotation 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.JsonProperty
annotation on the member itselfJsonProperty
annotation 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'sJsonNaming
annotation.- 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 jacksonBeanDescription
for 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 theBeanDescription
should 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'sJsonProperty
annotation 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'sJsonProperty
annotation 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'sJsonProperty
annotation 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
-
-