Class JSONUtil.JSONBuilder

  • Enclosing class:
    JSONUtil

    public static final class JSONUtil.JSONBuilder
    extends Object
    A builder to create JSON output.

    This class provides the most flexible way to create JSON output from a variety of input data.

    Since:
    Intrexx 7.0
    • Method Detail

      • writeJSONStartObject

        public void writeJSONStartObject()
                                  throws IOException
        Write an opening curly bracket {.
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONEndObject

        public void writeJSONEndObject()
                                throws IOException
        Write a closing curly bracket }.
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONStartArray

        public void writeJSONStartArray()
                                 throws IOException
        Write an opening square bracket [.
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONEndArray

        public void writeJSONEndArray()
                               throws IOException
        Write a closing square bracket ].
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONQuote

        public void writeJSONQuote()
                            throws IOException
        Write a double quotation mark ".
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONComma

        public void writeJSONComma()
                            throws IOException
        Write a comma ,.
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONColon

        public void writeJSONColon()
                            throws IOException
        Write a colon :.
        Throws:
        IOException - If an I/O error occurred.
      • writeJSON

        public void writeJSON​(Object p_obj)
                       throws IOException
        Write an object. The method mimics the JSON.stringify function as defined in the ECMAScript Language Scecification, 5.1 edition.
        Parameters:
        p_obj - The object to be written.
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONR

        public JSONUtil.JSONBuilder writeJSONR​(Object p_obj)
                                        throws IOException
        Write an object. The method mimics the JSON.stringify function as defined in the ECMAScript Language Scecification, 5.1 edition.
        Parameters:
        p_obj - The object to be written.
        Returns:
        This object.
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONPair

        public void writeJSONPair​(String p_strName,
                                  Object p_value)
                           throws IOException
        Write a name-value pair, e.g. "name":"value".
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONPairs

        public void writeJSONPairs​(Map<String,​? extends Object> p_map)
                            throws IOException
        Write the name-value pairs ("name":"value",...) of the given map.
        Parameters:
        p_map - A map containing the pairs.
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONPairsR

        public JSONUtil.JSONBuilder writeJSONPairsR​(Map<String,​? extends Object> p_map)
                                             throws IOException
        Write the name-value pairs ("name":"value",...) of the given map.
        Parameters:
        p_map - A map containing the pairs.
        Returns:
        This object.
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONPairs

        public void writeJSONPairs​(Object p_obj,
                                   List<? extends CharSequence> p_properties)
                            throws IOException
        Write name-value pairs ("name":"value",...) representing the given object's bean properties.
        Parameters:
        p_obj - The object.
        p_properties - A list of bean properties that should be written as name-value pairs.
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONPairsR

        public JSONUtil.JSONBuilder writeJSONPairsR​(Object p_obj,
                                                    List<? extends CharSequence> p_properties)
                                             throws IOException
        Write name-value pairs ("name":"value",...) representing the given object's bean properties.
        Parameters:
        p_obj - The object.
        p_properties - A list of bean properties that should be written as name-value pairs.
        Returns:
        This object.
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONObject

        public void writeJSONObject​(Object p_obj,
                                    List<CharSequence> p_properties)
                             throws IOException
        Write a JSON object with the given object's bean properties.
        Parameters:
        p_obj - The object.
        p_properties - A list of bean properties that should be written as name-value pairs.
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONObjectR

        public JSONUtil.JSONBuilder writeJSONObjectR​(Object p_obj,
                                                     Collection<? extends CharSequence> p_properties)
                                              throws IOException
        Write a JSON named object the given object's bean properties.
        Parameters:
        p_obj - The object.
        p_properties - A list of bean properties that should be written as name-value pairs.
        Returns:
        This object.
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONNamedObject

        public void writeJSONNamedObject​(Object p_obj,
                                         String p_strName,
                                         Collection<? extends CharSequence> p_properties)
                                  throws IOException
        Write a JSON named object the given object's bean properties.
        Parameters:
        p_obj - The object.
        p_strName - The name of the object.
        p_properties - A list of bean properties that should be written as name-value pairs.
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONNamedObjectR

        public JSONUtil.JSONBuilder writeJSONNamedObjectR​(Object p_obj,
                                                          String p_strName,
                                                          Collection<? extends CharSequence> p_properties)
                                                   throws IOException
        Write a JSON named object the given object's bean properties.
        Parameters:
        p_obj - The object.
        p_strName - The name of the object.
        p_properties - A list of bean properties that should be written as name-value pairs.
        Returns:
        This object.
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONEscape

        public void writeJSONEscape​(CharSequence p_chseq)
                             throws IOException
        Write a JSON-escaped character sequence.
        Parameters:
        p_chseq - The character sequence to be written.
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONEscapeR

        public JSONUtil.JSONBuilder writeJSONEscapeR​(CharSequence p_chseq)
                                              throws IOException
        Write a JSON-escaped character sequence.
        Parameters:
        p_chseq - The character sequence to be written.
        Returns:
        This object.
        Throws:
        IOException - If an I/O error occurred.
      • writeJSONEscape

        public void writeJSONEscape​(CharSequence p_chseq,
                                    int p_iStart,
                                    int p_iEnd)
                             throws IOException
        Write a JSON-escaped character subsequence.
        Parameters:
        p_chseq - The character sequence to be written.
        p_iStart - The index of the first character in the subsequence.
        p_iEnd - The index of the character following the last character in the subsequence.
        Throws:
        IOException - If an I/O error occurred.
        IllegalArgumentException - If the given character sequence is null.
      • writeJSONEscapeR

        public JSONUtil.JSONBuilder writeJSONEscapeR​(CharSequence p_chseq,
                                                     int p_iStart,
                                                     int p_iEnd)
                                              throws IOException
        Write a JSON-escaped character subsequence.
        Parameters:
        p_chseq - The character sequence to be written.
        p_iStart - The index of the first character in the subsequence.
        p_iEnd - The index of the character following the last character in the subsequence.
        Returns:
        This object.
        Throws:
        IOException - If an I/O error occurred.
        IllegalArgumentException - If the given character sequence is null.