Package jsonvalues

Class JsBinary

  • All Implemented Interfaces:
    JsValue

    public final class JsBinary
    extends JsPrimitive
    Represents an array of bytes. This type is not part of the Json specification. It it serialized into a string using Base64 encoding scheme. A JsBinary and a JsStr are equals if the string is the array of bytes encoded in base64. byte[] bytes = "foo".getBytes(); String base64 = Base64.getEncoder().encodeToString(bytes); JsBinary.of(bytes).equals(JsStr.of(base64)); // true
    • Field Detail

      • value

        public final byte[] value
      • prism

        public static final Prism<JsValue,​byte[]> prism
        prism between the sum type JsValue and JsBinary
    • Method Detail

      • of

        public static JsBinary of​(byte[] bytes)
        Creates a JsBinary from an array of bytes
        Parameters:
        bytes - the array of bytes
        Returns:
        an immutable JsBinary
      • of

        public static JsBinary of​(java.lang.String base64)
        Creates a JsBinary from an array of bytes encoded as a string in base64
        Parameters:
        base64 - the string
        Returns:
        an immutable JsBinary
        Throws:
        java.lang.IllegalArgumentException - if base64 is not in valid Base64 scheme
      • id

        public int id()
      • isBinary

        public boolean isBinary()
        Description copied from interface: JsValue
        Returns true if this JsValue is a JsBinary or a JsString which value is an array of
        Returns:
        true if this JsValue is a JsBinary or a JsString which value is an array of bytes encoded in base64
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object