java.lang.Object
org.shredzone.acme4j.toolbox.JSON
All Implemented Interfaces:
java.io.Serializable

public final class JSON
extends java.lang.Object
implements java.io.Serializable
A model containing a JSON result. The content is immutable.
See Also:
Serialized Form
  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    static class  JSON.Array
    Represents a JSON array.
    static class  JSON.Value
    A single JSON value.
  • Method Summary

    Modifier and Type Method Description
    boolean contains​(java.lang.String key)
    Checks if this object contains the given key.
    static JSON empty()
    Returns a JSON of an empty document.
    JSON.Value get​(java.lang.String key)
    Returns the JSON.Value of the given key.
    java.util.Set<java.lang.String> keySet()
    Returns a set of all keys of this object.
    static JSON parse​(java.io.InputStream in)
    Parses JSON from an InputStream.
    static JSON parse​(java.lang.String json)
    Parses JSON from a String.
    java.util.Map<java.lang.String,​java.lang.Object> toMap()
    Returns the content as unmodifiable Map.
    java.lang.String toString()
    Returns the content as JSON string.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Method Details

    • parse

      public static JSON parse​(java.io.InputStream in) throws java.io.IOException
      Parses JSON from an InputStream.
      Parameters:
      in - InputStream to read from. Will be closed after use.
      Returns:
      JSON of the read content.
      Throws:
      java.io.IOException
    • parse

      public static JSON parse​(java.lang.String json)
      Parses JSON from a String.
      Parameters:
      json - JSON string
      Returns:
      JSON of the read content.
    • empty

      public static JSON empty()
      Returns a JSON of an empty document.
      Returns:
      Empty JSON
    • keySet

      public java.util.Set<java.lang.String> keySet()
      Returns a set of all keys of this object.
      Returns:
      Set of keys
    • contains

      public boolean contains​(java.lang.String key)
      Checks if this object contains the given key.
      Parameters:
      key - Name of the key to check
      Returns:
      true if the key is present
    • get

      public JSON.Value get​(java.lang.String key)
      Returns the JSON.Value of the given key.
      Parameters:
      key - Key to read
      Returns:
      JSON.Value of the key
    • toString

      public java.lang.String toString()
      Returns the content as JSON string.
      Overrides:
      toString in class java.lang.Object
    • toMap

      public java.util.Map<java.lang.String,​java.lang.Object> toMap()
      Returns the content as unmodifiable Map.
      Since:
      2.8