Class JsonPropertySorter

java.lang.Object
com.github.victools.jsonschema.module.jackson.JsonPropertySorter
All Implemented Interfaces:
Comparator<com.github.victools.jsonschema.generator.MemberScope<?,?>>

public class JsonPropertySorter extends Object implements Comparator<com.github.victools.jsonschema.generator.MemberScope<?,?>>
Implementation of the sorting logic for an object's properties based on a JsonPropertyOrder annotation on the declaring type.
  • Constructor Details

    • JsonPropertySorter

      public JsonPropertySorter(boolean sortAlphabeticallyIfNotAnnotated)
      Constructor.
      Parameters:
      sortAlphabeticallyIfNotAnnotated - whether properties of a type without JsonPropertyOrder should be sorted alphabetically
  • Method Details

    • compare

      public int compare(com.github.victools.jsonschema.generator.MemberScope<?,?> first, com.github.victools.jsonschema.generator.MemberScope<?,?> second)
      Specified by:
      compare in interface Comparator<com.github.victools.jsonschema.generator.MemberScope<?,?>>
    • getPropertyIndex

      protected int getPropertyIndex(com.github.victools.jsonschema.generator.MemberScope<?,?> property)
      Determine the given property's position in its declaring type's schema based on a JsonPropertyOrder annotation. If no such annotation is present, Integer.MAX_VALUE will be returned to append these at the end of the list of properties.
      Parameters:
      property - field/method for which the respective index should be determined
      Returns:
      specific property index or Integer.MAX_VALUE
    • shouldSortPropertiesAlphabetically

      protected boolean shouldSortPropertiesAlphabetically(Class<?> declaringType)
      Determine whether the given type's properties that are not specifically mentioned in a JsonPropertyOrder annotation should be sorted alphabetically, based on JsonPropertyOrder.alphabetic(). If no such annotation is present, the value given in the JsonPropertySorter(boolean) constructor.
      Parameters:
      declaringType - type for which the properties' default sorting should be determined
      Returns:
      whether properties that are not specifically mentioned in a JsonPropertyOrder annotation should be sorted alphabetically