com.skaringa.json.parser
Class JsonParser

java.lang.Object
  extended by com.skaringa.json.parser.JsonParser

public class JsonParser
extends java.lang.Object

Parse JSON into Java objects.


Constructor Summary
JsonParser(java.io.Reader reader, java.lang.Class rootType, java.lang.ClassLoader classLoader)
          Create a new parser.
JsonParser(java.io.Reader reader, java.lang.Class rootType, java.util.Map propertyMap, java.lang.ClassLoader classLoader)
          Create a new parser.
 
Method Summary
 java.lang.ClassLoader getClassLoader()
          Get the class loader used to load classes during deserialization.
 java.lang.Object getObject()
          Get the deserialized object tree.
 void process()
          Parse the JSON and instantiate the Java object tree.
 void setClassLoader(java.lang.ClassLoader loader)
          Set the class loader used to load classes during deserialization.
 void setRootType(java.lang.Class type)
          Set the type of the root object to be deserialized.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonParser

public JsonParser(java.io.Reader reader,
                  java.lang.Class rootType,
                  java.lang.ClassLoader classLoader)
Create a new parser.

Parameters:
reader - The reader that produces the JSON.
rootType - The type of the root object. If null, then LinkedList or HashMap is used.
classLoader - The class loader used to instantiate the Java objects.

JsonParser

public JsonParser(java.io.Reader reader,
                  java.lang.Class rootType,
                  java.util.Map propertyMap,
                  java.lang.ClassLoader classLoader)
Create a new parser.

Parameters:
reader - The reader that produces the JSON.
rootType - The type of the root object. If null, then LinkedList or HashMap is used.
propertyMap - The properties to control the parsing.
classLoader - The class loader used to instantiate the Java objects.
Method Detail

process

public void process()
             throws java.io.IOException,
                    DeserializerException
Parse the JSON and instantiate the Java object tree.

Throws:
java.io.IOException - If the reader fails.
DeserializerException - If the desrialization failes (e.g. because of invalid JSON).

setRootType

public void setRootType(java.lang.Class type)
Set the type of the root object to be deserialized.

Parameters:
type - The class of the root object.

getObject

public java.lang.Object getObject()
Get the deserialized object tree. The type of object is the same as rootType. If rootType is null, then the type is Collection or Map depending on the JSON parsed.

Returns:
The new Object.

setClassLoader

public void setClassLoader(java.lang.ClassLoader loader)
Set the class loader used to load classes during deserialization.

Parameters:
loader - The class loader.

getClassLoader

public java.lang.ClassLoader getClassLoader()
Get the class loader used to load classes during deserialization.

Returns:
The class loader.