org.elkoserver.foundation.json
Class ObjectDecoder

java.lang.Object
  extended by org.elkoserver.foundation.json.ObjectDecoder

public class ObjectDecoder
extends Object

A producer of some class of Java objects from JSON-encoded object descriptors.


Method Summary
static Object decode(Class baseType, JSONObject jsonObj)
          A simple JSON object decoder for one-shot objects.
static Object decode(Class baseType, JSONObject obj, TypeResolver resolver)
          Produce the Java object described by a particular JSON object descriptor.
static Object decode(Class baseType, String str)
          A simple JSON string decoder for one-shot objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

decode

public static Object decode(Class baseType,
                            JSONObject obj,
                            TypeResolver resolver)
Produce the Java object described by a particular JSON object descriptor.

Parameters:
baseType - The desired class of the resulting Java object. The result will not necessarily be of this class, but will be assignable to a variable of this class.
obj - The parsed JSON object descriptor to be decoded.
resolver - An object mapping type tag strings to Java classes.
Returns:
a new Java object assignable to the class in 'baseType' as described by 'obj', or null if the object could not be decoded for some reason.

decode

public static Object decode(Class baseType,
                            JSONObject jsonObj)
A simple JSON object decoder for one-shot objects. The given object is by the decode(Class,JSONObject,TypeResolver) method, using the StaticTypeResolver to resolve type tags.

Parameters:
baseType - The desired class of the resulting Java object. The result will not necessarily be of this class, but will be assignable to a variable of this class.
jsonObj - A JSON object describing the object to decode.
Returns:
a new Java object assignable to the class in 'baseType' as described by 'jsonObj', or null if the object could not be decoded for some reason.

decode

public static Object decode(Class baseType,
                            String str)
A simple JSON string decoder for one-shot objects. The given string is first parsed, and then decoded as by the decode(Class,JSONObject,TypeResolver) method, using the StaticTypeResolver to resolve type tags.

Parameters:
baseType - The desired class of the resulting Java object. The result will not necessarily be of this class, but will be assignable to a variable of this class.
str - A JSON string describing the object.
Returns:
a new Java object assignable to the class in 'baseType' as described by 'str', or null if the string was syntactically malformed or the object could not be decoded for some reason.