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

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

public class JsonParser
extends java.lang.Object

JSON parser.

This class provides some methods for generating parsing JSON text and create objects out of it. It uses a factory to deal with the actual object classes.


Nested Class Summary
static interface JsonParser.ParseCallback
          Callback when a stream of json entries is parsed
 
Constructor Summary
JsonParser()
           
 
Method Summary
static java.lang.Object fromJson(JsonFactory factory, java.io.Reader reader)
          Parse a JSON stream and return an object.
static void fromJson(JsonFactory factory, java.io.Reader reader, JsonParser.ParseCallback cb)
          Parse a JSON stream and call a function for each entry.
static void fromJson(JsonFactory factory, java.io.Reader reader, java.util.List<java.lang.Object> list)
          Parse a JSON stream and add all the entries to a list.
static java.lang.Object fromJson(JsonFactory factory, java.lang.String json)
          Parse a JSON text and return an object.
static boolean isJson(java.lang.String json)
          Check if a string a a valid JSON text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonParser

public JsonParser()
Method Detail

isJson

public static boolean isJson(java.lang.String json)
Check if a string a a valid JSON text.

Parameters:
json - the JSON text to check
Returns:
true if the string is a JSON object
Throws:
JsonException

fromJson

public static java.lang.Object fromJson(JsonFactory factory,
                                        java.lang.String json)
                                 throws JsonException
Parse a JSON text and return an object.

Parameters:
factory - the object factory
json - the JSON text
Returns:
the object created from the JSON text
Throws:
JsonException

fromJson

public static java.lang.Object fromJson(JsonFactory factory,
                                        java.io.Reader reader)
                                 throws JsonException
Parse a JSON stream and return an object.

Parameters:
factory - the object factory
reader - the JSON stream
Returns:
the object created from the JSON text
Throws:
JsonException

fromJson

public static void fromJson(JsonFactory factory,
                            java.io.Reader reader,
                            java.util.List<java.lang.Object> list)
                     throws JsonException
Parse a JSON stream and add all the entries to a list.

Parameters:
factory - the object factory
reader - the JSON stream
cb - the cllback to call for each entry
Throws:
JsonException

fromJson

public static void fromJson(JsonFactory factory,
                            java.io.Reader reader,
                            JsonParser.ParseCallback cb)
                     throws JsonException
Parse a JSON stream and call a function for each entry.

Parameters:
factory - the object factory
reader - the JSON stream
cb - the cllback to call for each entry
Throws:
JsonException