Class JsonPropertySorter
- java.lang.Object
-
- com.github.victools.jsonschema.module.jackson.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 aJsonPropertyOrder
annotation on the declaring type.
-
-
Constructor Summary
Constructors Constructor Description JsonPropertySorter(boolean sortAlphabeticallyIfNotAnnotated)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(MemberScope<?,?> first, MemberScope<?,?> second)
protected int
getPropertyIndex(MemberScope<?,?> property)
Determine the given property's position in its declaring type's schema based on aJsonPropertyOrder
annotation.protected boolean
shouldSortPropertiesAlphabetically(Class<?> declaringType)
Determine whether the given type's properties that are not specifically mentioned in aJsonPropertyOrder
annotation should be sorted alphabetically, based onJsonPropertyOrder.alphabetic()
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Method Detail
-
compare
public int compare(MemberScope<?,?> first, MemberScope<?,?> second)
- Specified by:
compare
in interfaceComparator<MemberScope<?,?>>
-
getPropertyIndex
protected int getPropertyIndex(MemberScope<?,?> property)
Determine the given property's position in its declaring type's schema based on aJsonPropertyOrder
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 aJsonPropertyOrder
annotation should be sorted alphabetically, based onJsonPropertyOrder.alphabetic()
. If no such annotation is present, the value given in theJsonPropertySorter(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
-
-