Class JSONRenderer


  • @Deprecated
    public class JSONRenderer
    extends Object
    Deprecated.
    Various JSON-to-String primitives, used by other classes when outputting/formatting JSON. Streaming variants of some methods are provided. The existing code in this module is often not streaming, but we should write newer code using streams, as much as possible.
    • Constructor Detail

      • JSONRenderer

        public JSONRenderer()
        Deprecated.
    • Method Detail

      • options

        public JSONRenderer.Options options()
        Deprecated.
        Return an Options object with default values
      • toString

        public String toString​(JSONObject jo)
        Deprecated.
        Render the supplied JSONObject to a String, in the simplest possible way.
      • toString

        public String toString​(JSONArray ja)
        Deprecated.
        Make a JSON text of the supplied JSONArray. For compactness, no unnecessary whitespace is added. If it is not possible to produce a syntactically correct JSON text then null will be returned instead. This could occur if the array contains an invalid number.

        Warning: This method assumes that the data structure is acyclical.

        Returns:
        a printable, displayable, transmittable representation of the array.
      • quote

        public String quote​(String string)
        Deprecated.
        Quote the supplied string for JSON
      • valueToString

        public String valueToString​(Object value)
                             throws JSONException
        Deprecated.
        Make a JSON text of an Object value. If the object has an value.toJSONString() method, then that method will be used to produce the JSON text. The method is required to produce a strictly conforming text. If the object does not contain a toJSONString method (which is the most common case), then a text will be produced by the rules.

        Warning: This method assumes that the data structure is acyclical.

        Parameters:
        value - The value to be serialized.
        Returns:
        a printable, displayable, transmittable representation of the object, beginning with { (left brace) and ending with } (right brace).
        Throws:
        JSONException - If the value is or contains an invalid number.
      • valueToString

        public String valueToString​(Object value,
                                    JSONRenderer.Options opt)
                             throws JSONException
        Deprecated.
        Make a JSON String of an Object value, with rendering options

        Warning: This method assumes that the data structure is acyclical.

        Parameters:
        value - The value to be serialized.
        Returns:
        a printable, displayable, transmittable representation of the object, beginning with { (left brace) and ending with } (right brace).
        Throws:
        JSONException - If the object contains an invalid number.
      • numberToString

        public String numberToString​(Number n)
                              throws JSONException
        Deprecated.
        Produce a string from a Number.
        Parameters:
        n - A Number
        Returns:
        A String.
        Throws:
        JSONException - If n is a non-finite number.
      • prettyPrint

        public String prettyPrint​(JSONObject jo,
                                  JSONRenderer.Options opt)
                           throws JSONException
        Deprecated.
        Make a prettyprinted JSON text of this JSONObject.

        Warning: This method assumes that the data structure is acyclical.

        Returns:
        a printable, displayable, transmittable representation of the object, beginning with { (left brace) and ending with } (right brace).
        Throws:
        JSONException - If the object contains an invalid number.
      • testNumberValidity

        public void testNumberValidity​(Object o)
                                throws JSONException
        Deprecated.
        Throw an exception if the object is an NaN or infinite number.
        Parameters:
        o - The object to test.
        Throws:
        JSONException - If o is a non-finite number.
      • join

        public String join​(JSONArray ja,
                           String separator)
                    throws JSONException
        Deprecated.
        Make a string from the contents of this JSONArray. The separator string is inserted between each element. Warning: This method assumes that the data structure is acyclical.
        Parameters:
        separator - A string that will be inserted between the elements.
        Returns:
        a string.
        Throws:
        JSONException - If the array contains an invalid number.
      • write

        public Writer write​(Writer writer,
                            JSONObject jo)
                     throws JSONException
        Deprecated.
        Write the contents of the supplied JSONObject as JSON text to a writer. For compactness, no whitespace is added.

        Warning: This method assumes that the data structure is acyclical.

        Returns:
        The writer.
        Throws:
        JSONException
      • write

        public Writer write​(Writer writer,
                            JSONArray ja)
                     throws JSONException
        Deprecated.
        Write the contents of the supplied JSONArray as JSON text to a writer. For compactness, no whitespace is added.

        Warning: This method assumes that the data structure is acyclical.

        Returns:
        The writer.
        Throws:
        JSONException
      • doubleToString

        public String doubleToString​(double d)
        Deprecated.
        Produce a string from a double. The string "null" will be returned if the number is not finite.
        Parameters:
        d - A double.
        Returns:
        A String.