com.ibm.commons.util.io.json
Class JsonGenerator

java.lang.Object
  extended by com.ibm.commons.util.io.json.JsonGenerator

public class JsonGenerator
extends java.lang.Object

JSON text generator.

This class provides some methods for generating JSON object representation. It uses a factory to deal with the actual object classes.


Nested Class Summary
static class JsonGenerator.Generator
          Generator base class.
static class JsonGenerator.StringBuilderGenerator
          StringBuilder generator class.
static class JsonGenerator.StringGenerator
          String generator class.
static class JsonGenerator.WriterGenerator
          Writer generator class.
 
Constructor Summary
JsonGenerator()
           
 
Method Summary
static java.lang.String toJson(JsonFactory factory, java.lang.Object value)
          Convert an object hierarchy to a JSON text.
static java.lang.String toJson(JsonFactory factory, java.lang.Object value, boolean compact)
          Convert an object hierarchy to a JSON text.
static java.lang.StringBuilder toJson(JsonFactory factory, java.lang.StringBuilder b, java.lang.Object value, boolean compact)
          Convert an object hierarchy to a JSON text and append it to an existing String builder.
static void toJson(JsonFactory factory, java.io.Writer writer, java.lang.Object value, boolean compact)
          Convert an object hierarchy to a JSON text in a writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonGenerator

public JsonGenerator()
Method Detail

toJson

public static java.lang.String toJson(JsonFactory factory,
                                      java.lang.Object value)
                               throws java.io.IOException,
                                      JsonException
Convert an object hierarchy to a JSON text. The string is written in a compact form (no extra spaces/new lines inserted).

Parameters:
factory - the object factory
value - the convert to serialize
Returns:
the resulting JSON string
Throws:
java.io.IOException
JsonException

toJson

public static java.lang.String toJson(JsonFactory factory,
                                      java.lang.Object value,
                                      boolean compact)
                               throws java.io.IOException,
                                      JsonException
Convert an object hierarchy to a JSON text.

Parameters:
factory - the object factory
value - the convert to serialize
compact - indicates if the string should be in a compact format
Returns:
the resulting JSON string
Throws:
java.io.IOException
JsonException

toJson

public static java.lang.StringBuilder toJson(JsonFactory factory,
                                             java.lang.StringBuilder b,
                                             java.lang.Object value,
                                             boolean compact)
                                      throws java.io.IOException,
                                             JsonException
Convert an object hierarchy to a JSON text and append it to an existing String builder.

Parameters:
factory - the object factory
b - the StringBuilder to append the text to
value - the convert to serialize
compact - indicates if the string should be in a compact format
Returns:
the resulting JSON string
Throws:
java.io.IOException
JsonException

toJson

public static void toJson(JsonFactory factory,
                          java.io.Writer writer,
                          java.lang.Object value,
                          boolean compact)
                   throws java.io.IOException,
                          JsonException
Convert an object hierarchy to a JSON text in a writer.

Parameters:
factory - the object factory
writer - the writer to write to
value - the convert to serialize
compact - indicates if the string should be in a compact format
Throws:
java.io.IOException
JsonException