Class CanonicalJsonFormatter


  • public final class CanonicalJsonFormatter
    extends java.lang.Object
    Json serializer with canonicalization. Ensures deterministic encoding for consistent hashing purposes. Serializes a json node object in a canonical deterministic encoding. This encoding must never be changed to avoid inconsistent hashing of previously encoded data. String literals are encoded as follows in the format '"char1char2..."' - Simple escaping is applied for and only for the following characters : '"', '\\', '\b', '\f', \n', '\r' & '\t'. - Printable ascii chars are not escaped [32 - 127] - 4 digit hex escaping for any other character (ሴ). Integer literals are encoded as is (0, 1234, -1234) Floating numbers are formatted using Double.format() Arrays are encoded is the '[entry1,entry2...]' format. Objects entries are encoded with sorted keys in the '{"key1":value1,...)}' No pretty-printing is appended (no line breaks or spacing is appended).
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.io.InputStream serialize​(com.fasterxml.jackson.databind.JsonNode node)
      Serializes a json node object in a canonical deterministic encoding.
      static void serialize​(com.fasterxml.jackson.databind.JsonNode node, java.io.OutputStream outputStream)
      Serializes a json node object in a canonical deterministic encoding.
      static byte[] serializeToByteArray​(com.fasterxml.jackson.databind.JsonNode node)
      Serializes a json node object in a canonical deterministic encoding.
      • Methods inherited from class java.lang.Object

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

      • serialize

        public static java.io.InputStream serialize​(com.fasterxml.jackson.databind.JsonNode node)
        Serializes a json node object in a canonical deterministic encoding.
        Parameters:
        node - the json node
      • serializeToByteArray

        public static byte[] serializeToByteArray​(com.fasterxml.jackson.databind.JsonNode node)
        Serializes a json node object in a canonical deterministic encoding.
        Parameters:
        node - the json node
      • serialize

        public static void serialize​(com.fasterxml.jackson.databind.JsonNode node,
                                     java.io.OutputStream outputStream)
                              throws java.io.IOException
        Serializes a json node object in a canonical deterministic encoding.
        Parameters:
        node - the json node
        outputStream - output stream to which json node is serialized.
        Throws:
        java.io.IOException