Module json_values
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 is 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 Details

    • prism

      public static final fun.optic.Prism<JsValue,byte[]> prism
      prism between the sum type JsValue and JsBinary
    • value

      public final byte[] value
      the array of bytes
  • Method Details

    • 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(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:
      IllegalArgumentException - if base64 is not in valid Base64 scheme
    • toJsPrimitive

      public JsPrimitive toJsPrimitive()
    • 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 String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object