Class JacksonModule

  • All Implemented Interfaces:
    Module

    public class JacksonModule
    extends Object
    implements Module
    Module for setting up schema generation aspects based on jackson-annotations.
    • Populate the "description" attributes as per JsonPropertyDescription and JsonClassDescription 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 Detail

      • JacksonModule

        public JacksonModule​(JacksonOption... options)
        Constructor.
        Parameters:
        options - features to enable
    • Method Detail

      • resolveDescription

        protected String resolveDescription​(MemberScope<?,​?> member)
        Determine the given member's associated "description" in the following order of priority.
        1. JsonPropertyDescription annotation on the field/method itself
        2. JsonPropertyDescription 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.
        1. JsonProperty annotation on the member itself
        2. JsonProperty 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's JsonNaming 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 jackson BeanDescription 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 the BeanDescription 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's JsonProperty 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's JsonProperty 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's JsonProperty 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