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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcompare(com.github.victools.jsonschema.generator.MemberScope<?, ?> first, com.github.victools.jsonschema.generator.MemberScope<?, ?> second) protected intgetPropertyIndex(com.github.victools.jsonschema.generator.MemberScope<?, ?> property) Determine the given property's position in its declaring type's schema based on aJsonPropertyOrderannotation.protected booleanshouldSortPropertiesAlphabetically(Class<?> declaringType) Determine whether the given type's properties that are not specifically mentioned in aJsonPropertyOrderannotation should be sorted alphabetically, based onJsonPropertyOrder.alphabetic().Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
JsonPropertySorter
public JsonPropertySorter(boolean sortAlphabeticallyIfNotAnnotated) Constructor.- Parameters:
sortAlphabeticallyIfNotAnnotated- whether properties of a type withoutJsonPropertyOrdershould 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:
comparein interfaceComparator<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 aJsonPropertyOrderannotation. If no such annotation is present,Integer.MAX_VALUEwill 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
Determine whether the given type's properties that are not specifically mentioned in aJsonPropertyOrderannotation 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
JsonPropertyOrderannotation should be sorted alphabetically
-