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 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 Summary

    Constructors
    Constructor
    Description
    Constructor, without any additional options.
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    applyToConfigBuilder(com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder builder)
     
    protected final tools.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.
    protected String
    getPropertyNameOverrideBasedOnJsonNamingAnnotation(com.github.victools.jsonschema.generator.FieldScope field)
    Alter the declaring name of the given field as per the declaring type's JsonNaming annotation.
    protected String
    getPropertyNameOverrideBasedOnJsonPropertyAnnotation(com.github.victools.jsonschema.generator.MemberScope<?,?> member)
    Look-up an alternative name as per the following order of priority.
    protected boolean
    getReadOnlyCheck(com.github.victools.jsonschema.generator.MemberScope<?,?> member)
    Determine whether the given field's/method's JsonProperty annotation marks it as read-only.
    protected boolean
    getRequiredCheckBasedOnJsonPropertyAnnotation(com.github.victools.jsonschema.generator.MemberScope<?,?> member)
    Look-up the given field's/method's JsonProperty annotation and consider its "required" attribute.
    protected boolean
    getWriteOnlyCheck(com.github.victools.jsonschema.generator.MemberScope<?,?> member)
    Determine whether the given field's/method's JsonProperty annotation marks it as write-only.
    protected String
    resolveDescription(com.github.victools.jsonschema.generator.MemberScope<?,?> member)
    Determine the given member's associated "description" in the following order of priority.
    protected String
    resolveDescriptionForType(com.github.victools.jsonschema.generator.TypeScope scope)
    Determine the given type's associated "description" via the following annotation.
    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.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JacksonSchemaModule

      public JacksonSchemaModule()
      Constructor, without any additional options.
      See Also:
    • JacksonSchemaModule

      public JacksonSchemaModule(JacksonOption... options)
      Constructor.
      Parameters:
      options - features to enable
  • Method Details

    • applyToConfigBuilder

      public void applyToConfigBuilder(com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder builder)
      Specified by:
      applyToConfigBuilder in interface com.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.
      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(com.github.victools.jsonschema.generator.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(com.github.victools.jsonschema.generator.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(com.github.victools.jsonschema.generator.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 tools.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(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'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(com.github.victools.jsonschema.generator.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(com.github.victools.jsonschema.generator.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