public class JSONSort
extends java.lang.Object
Constructor and Description |
---|
JSONSort(java.util.Comparator<java.lang.String> keyComparator)
Creates the sorter
|
JSONSort(java.util.Comparator<java.lang.String> keyComparator,
boolean prettyOutput)
Creates the sorter
|
JSONSort(java.util.Comparator<java.lang.String> keyComparator,
java.util.Comparator<java.lang.Object> arrayValueComparator)
Creates the sorter
|
JSONSort(java.util.Comparator<java.lang.String> keyComparator,
java.util.Comparator<java.lang.Object> arrayValueComparator,
boolean prettyOutput)
Creates the sorter
|
Modifier and Type | Method and Description |
---|---|
boolean |
isPrettyOutput()
Returns the PrettyOutput for the object
|
java.lang.String |
parseAndSort(java.lang.String jsonString)
Takes the JSON string as input and parses it, then sorts it and returns the new output
|
void |
setPrettyOutput(boolean prettyOutput)
Sets the PrettyOutput for the object
|
java.lang.String |
toSortedString(java.lang.Object obj)
Converts the object to a JSON string, but it will be sorted according to the comparators of this object
|
public JSONSort(@NotNull java.util.Comparator<java.lang.String> keyComparator)
keyComparator
- The comparator for comparing keyspublic JSONSort(@NotNull java.util.Comparator<java.lang.String> keyComparator, boolean prettyOutput)
keyComparator
- The comparator for comparing keysprettyOutput
- True if output should be pretty (new lines, spacing, etc...) or false for a more compact JSON stringpublic JSONSort(@NotNull java.util.Comparator<java.lang.String> keyComparator, @Nullable java.util.Comparator<java.lang.Object> arrayValueComparator)
keyComparator
- The comparator for comparing keysarrayValueComparator
- The comparator for comparing values in an array (null means leaves arrays in the order they are in)public JSONSort(@NotNull java.util.Comparator<java.lang.String> keyComparator, @Nullable java.util.Comparator<java.lang.Object> arrayValueComparator, boolean prettyOutput)
keyComparator
- The comparator for comparing keysarrayValueComparator
- The comparator for comparing values in an array (null means leaves arrays in the order they are in)prettyOutput
- True if output should be pretty (new lines, spacing, etc...) or false for a more compact JSON stringpublic boolean isPrettyOutput()
public void setPrettyOutput(boolean prettyOutput)
prettyOutput
- The new value for PrettyOutput@NotNull public java.lang.String parseAndSort(@NotNull java.lang.String jsonString)
jsonString
- The json to parse@NotNull public java.lang.String toSortedString(@Nullable java.lang.Object obj)
obj
- The object to sort (must be a valid JSON type -- JSONObject, JSONArray, String, Boolean, Number) from org.json.*