EZ JSON
by Nathanaël Cottin

org.ezjson
Class JSONEncoder

java.lang.Object
  extended by org.ezjson.JSONEncoder

public final class JSONEncoder
extends java.lang.Object

Default JSON encoder to serialize JSON objects

Author:
ncottin

Field Summary
static char SPACE
          Indentation for a pretty encoding using a space character
static char TABULATION
          Indentation for a pretty encoding using a tabulation character
 
Constructor Summary
JSONEncoder()
           
 
Method Summary
static void encode(JSONObject obj, java.io.PrintWriter out)
          Serializes a JSON object to a destination writer using the most compact format.
static void encodePretty(JSONObject obj, char spacer, java.io.PrintWriter out)
          Serializes a JSON object using a human-readble encoding (which includes a pretty indentation) with no initial indentation
static void encodePretty(JSONObject obj, int offset, char spacer, java.io.PrintWriter out)
          Serializes a JSON object using a human-readble encoding (which includes a pretty indentation) with an initial indentation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPACE

public static final char SPACE
Indentation for a pretty encoding using a space character

See Also:
Constant Field Values

TABULATION

public static final char TABULATION
Indentation for a pretty encoding using a tabulation character

See Also:
Constant Field Values
Constructor Detail

JSONEncoder

public JSONEncoder()
Method Detail

encode

public static void encode(JSONObject obj,
                          java.io.PrintWriter out)
                   throws java.io.IOException
Serializes a JSON object to a destination writer using the most compact format. This encoding is primarily designed for machine-to-machine communications and may not be easily readable

Parameters:
obj - The non-null source JSON object to serialize
out - The destination writer to receive the serialized form of the provided JSON object
Throws:
java.io.IOException - The destination writer could not be written
See Also:
encodePretty(org.ezjson.JSONObject, char, java.io.PrintWriter)

encodePretty

public static void encodePretty(JSONObject obj,
                                char spacer,
                                java.io.PrintWriter out)
                         throws java.io.IOException
Serializes a JSON object using a human-readble encoding (which includes a pretty indentation) with no initial indentation

Parameters:
obj - The non-null source JSON object to serialize
spacer - A space character used for indentation, among SPACE and TABULATION
out - The destination writer to receive the serialized form of the provided JSON object
Throws:
java.io.IOException - Writing to the destination writer failed

encodePretty

public static void encodePretty(JSONObject obj,
                                int offset,
                                char spacer,
                                java.io.PrintWriter out)
                         throws java.io.IOException
Serializes a JSON object using a human-readble encoding (which includes a pretty indentation) with an initial indentation. This initial indentation corresponds to the root JSON object indentation

Parameters:
obj -
offset - The initial indentation expressed with a positive number of space characters
spacer - A space character used for indentation, among SPACE and TABULATION
out - out The destination writer to receive the serialized form of the provided JSON object
Throws:
java.io.IOException - Writing to the destination writer failed

EZ JSON
by Nathanaël Cottin