Class JSONSerializer


  • public class JSONSerializer
    extends Object
    Author:
    FangYidong
    • Constructor Detail

      • JSONSerializer

        public JSONSerializer()
    • Method Detail

      • writeJSONString

        public static void writeJSONString​(Object value,
                                           Writer out)
                                    throws IOException
        Encode an object into JSON text and write it to out.

        If this object is a Map or a List, and it's also a JSONStreamAware or a JSONAware, JSONStreamAware or JSONAware will be considered firstly.

        DO NOT call this method from writeJSONString(Writer) of a class that implements both JSONStreamAware and (Map or List) with "this" as the first parameter, use JSONObject.writeJSONString(Map, Writer) or JSONArray.writeJSONString(List, Writer) instead.

        Parameters:
        value -
        writer -
        Throws:
        IOException
        See Also:
        JSONObject.writeJSONString(Map, Writer), JSONArray.writeJSONString(List, Writer)
      • writeJSONString

        public static void writeJSONString​(Map map,
                                           Writer out)
                                    throws IOException
        Encode a map into JSON text and write it to out. If this map is also a JSONAware or JSONStreamAware, JSONAware or JSONStreamAware specific behaviours will be ignored at this top level.
        Parameters:
        map -
        out -
        Throws:
        IOException
        See Also:
        JSONValue.writeJSONString(Object, Writer)
      • writeJSONString

        public static void writeJSONString​(Collection list,
                                           Writer out)
                                    throws IOException
        Encode a list into JSON text and write it to out. If this list is also a JSONStreamAware or a JSONAware, JSONStreamAware and JSONAware specific behaviours will be ignored at this top level.
        Parameters:
        list -
        out -
        Throws:
        IOException
        See Also:
        JSONValue.writeJSONString(Object, Writer)
      • escape

        public static String escape​(String s)
        Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).
        Parameters:
        s -
        Returns: