Class JsIO

java.lang.Object
jsonvalues.spec.JsIO

public final class JsIO extends Object
Singleton instance to create JSON readers and writers to parse bytes into JSON and serialize JSON into bytes. Only a few a methods are exposed since this class is vastly used internally. You may be interested in creating JsReaders only to parse bytes or strings token by token.
See Also:
  • Field Details

    • INSTANCE

      public static final JsIO INSTANCE
      Singleton instance
  • Method Details

    • parseToJsObj

      public JsObj parseToJsObj(byte[] bytes)
      Parses the given array of bytes into an immutable and persistent JSON object.
      Parameters:
      bytes - the array of bytes
      Returns:
      a JsObj object
      Throws:
      JsParserException - if the string doesn't represent a json object
    • parseToJsArray

      public JsArray parseToJsArray(byte[] bytes)
      Parses the given array of bytes into an immutable and persistent JSON array.
      Parameters:
      bytes - the array of bytes
      Returns:
      a JsArray object
      Throws:
      JsParserException - if the string doesn't represent a json object
    • serialize

      public byte[] serialize(Json<?> json) throws JsSerializerException
      Serializes the specified JSON into an array of bytes
      Parameters:
      json - the JSON
      Returns:
      an array of bytes
      Throws:
      JsSerializerException
    • serialize

      public void serialize(Json<?> json, OutputStream stream) throws JsSerializerException
      Serializes the specified JSON into the given output stream
      Parameters:
      json - the JSON
      stream - the stream
      Throws:
      JsSerializerException
    • toPrettyString

      public String toPrettyString(Json<?> json, int indentLength)
      Serializes a JSON into a formatted string
      Parameters:
      json - the json
      indentLength - the indentation length
      Returns:
      a string representation of the JSON