Class Sortr

  • All Implemented Interfaces:
    JoltTransform, Transform

    public class Sortr
    extends java.lang.Object
    implements Transform
    Recursively sorts all maps within a JSON object into new sorted LinkedHashMaps so that serialized representations are deterministic. Useful for debugging and making test fixtures. Note this will make a copy of the input Map and List objects. The sort order is standard alphabetical ascending, with a special case for "~" prefixed keys to be bumped to the top.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  Sortr.JsonKeyComparator
      Standard alphabetical sort, with a special case for keys beginning with "~".
    • Constructor Summary

      Constructors 
      Constructor Description
      Sortr()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.util.List<java.lang.Object> ordered​(java.util.List<java.lang.Object> list)  
      static java.lang.Object sortJson​(java.lang.Object obj)  
      private static java.util.Map<java.lang.String,​java.lang.Object> sortMap​(java.util.Map<java.lang.String,​java.lang.Object> map)  
      java.lang.Object transform​(java.lang.Object input)
      Makes a "sorted" copy of the input JSON for human readability.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Sortr

        public Sortr()
    • Method Detail

      • transform

        public java.lang.Object transform​(java.lang.Object input)
        Makes a "sorted" copy of the input JSON for human readability.
        Specified by:
        transform in interface Transform
        Parameters:
        input - the JSON object to transform, in plain vanilla Jackson Map style
        Returns:
        the results of the transformation
      • sortJson

        public static java.lang.Object sortJson​(java.lang.Object obj)
      • sortMap

        private static java.util.Map<java.lang.String,​java.lang.Object> sortMap​(java.util.Map<java.lang.String,​java.lang.Object> map)
      • ordered

        private static java.util.List<java.lang.Object> ordered​(java.util.List<java.lang.Object> list)