Class JSON


  • public class JSON
    extends java.lang.Object
    Helper class that does generic parsing of a JSON stream and returns the appropriate JSON structure (JSONArray or JSONObject). Note that it is slightly more efficient to directly parse with the appropriate object than to use this class to do a generalized parse.
    • Constructor Summary

      Constructors 
      Constructor Description
      JSON()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static JSONArtifact parse​(java.io.InputStream is)
      Parse an InputStream of JSON text into a JSONArtifact.
      static JSONArtifact parse​(java.io.InputStream is, boolean order)
      Parse a InputStream of JSON text into a JSONArtifact.
      static JSONArtifact parse​(java.io.Reader reader)
      Parse a Reader of JSON text into a JSONArtifact.
      static JSONArtifact parse​(java.io.Reader reader, boolean order)
      Parse a Reader of JSON text into a JSONArtifact.
      static JSONArtifact parse​(java.lang.String str)
      Parse a string of JSON text into a JSONArtifact.
      static JSONArtifact parse​(java.lang.String str, boolean order)
      Parse a string of JSON text into a JSONArtifact.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JSON

        public JSON()
    • Method Detail

      • parse

        public static JSONArtifact parse​(java.io.Reader reader,
                                         boolean order)
                                  throws java.io.IOException,
                                         java.lang.NullPointerException
        Parse a Reader of JSON text into a JSONArtifact.
        Parameters:
        reader - The character reader to read the JSON data from.
        order - Boolean flag indicating if the order of the JSON data should be preserved. This parameter only has an effect if the stream is JSON Object { ... } formatted data. Note that the provided reader is not closed on completion of read; that is left to the caller.
        Returns:
        Returns an instance of JSONArtifact (JSONObject, OrderedJSONObject, or JSONArray), corrisponding to if the input stream was Object or Array notation.
        Throws:
        java.io.IOException - Thrown on IO errors during parse.
        java.lang.NullPointerException - Thrown if reader is null
      • parse

        public static JSONArtifact parse​(java.io.Reader reader)
                                  throws java.io.IOException,
                                         java.lang.NullPointerException
        Parse a Reader of JSON text into a JSONArtifact. This call is the same as JSON.parse(reader, false). Note that the provided reader is not closed on completion of read; that is left to the caller.
        Parameters:
        reader - The character reader to read the JSON data from.
        Returns:
        Returns an instance of JSONArtifact (JSONObject, OrderedJSONObject, or JSONArray), corrisponding to if the input stream was Object or Array notation.
        Throws:
        java.io.IOException - Thrown on IO errors during parse.
        java.lang.NullPointerException - Thrown if reader is null
      • parse

        public static JSONArtifact parse​(java.io.InputStream is,
                                         boolean order)
                                  throws java.io.IOException,
                                         java.lang.NullPointerException
        Parse a InputStream of JSON text into a JSONArtifact. Note that the provided InputStream is not closed on completion of read; that is left to the caller.
        Parameters:
        is - The input stream to read from. The content is assumed to be UTF-8 encoded and handled as such.
        order - Boolean flag indicating if the order of the JSON data should be preserved. This parameter only has an effect if the stream is JSON Object { ... } formatted data.
        Returns:
        Returns an instance of JSONArtifact (JSONObject or JSONArray), corrisponding to if the input stream was Object or Array notation.
        Throws:
        java.io.IOException - Thrown on IO errors during parse.
        java.lang.NullPointerException - Thrown if reader is null
      • parse

        public static JSONArtifact parse​(java.io.InputStream is)
                                  throws java.io.IOException,
                                         java.lang.NullPointerException
        Parse an InputStream of JSON text into a JSONArtifact. This call is the same as JSON.parse(is, false). Note that the provided InputStream is not closed on completion of read; that is left to the caller.
        Parameters:
        is - The input stream to read from. The content is assumed to be UTF-8 encoded and handled as such.
        Returns:
        Returns an instance of JSONArtifact (JSONObject, OrderedJSONObject, or JSONArray), corrisponding to if the input stream was Object or Array notation.
        Throws:
        java.io.IOException - Thrown on IO errors during parse.
        java.lang.NullPointerException - Thrown if reader is null
      • parse

        public static JSONArtifact parse​(java.lang.String str,
                                         boolean order)
                                  throws java.io.IOException,
                                         java.lang.NullPointerException
        Parse a string of JSON text into a JSONArtifact.
        Parameters:
        str - The String to read from.
        order - Boolean flag indicating if the order of the JSON data should be preserved. This parameter only has an effect if the stream is JSON Object { ... } formatted data.
        Returns:
        Returns an instance of JSONArtifact (JSONObject or JSONArray), corrisponding to if the input stream was Object or Array notation.
        Throws:
        java.io.IOException - Thrown on IO errors during parse.
        java.lang.NullPointerException - Thrown if str is null
      • parse

        public static JSONArtifact parse​(java.lang.String str)
                                  throws java.io.IOException,
                                         java.lang.NullPointerException
        Parse a string of JSON text into a JSONArtifact. This call is the same as JSON.parse(str, false).
        Parameters:
        str - The String to read from.
        Returns:
        Returns an instance of JSONArtifact (JSONObject, OrderedJSONObject, or JSONArray), corrisponding to if the input stream was Object or Array notation.
        Throws:
        java.io.IOException - Thrown on IO errors during parse.
        java.lang.NullPointerException - Thrown if str is null