Class JsonPropertySorter

  • All Implemented Interfaces:
    Comparator<MemberScope<?,​?>>

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

      • JsonPropertySorter

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

      • getPropertyIndex

        protected int getPropertyIndex​(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