com.metaparadigm.jsonrpc
Class JSONSerializer

java.lang.Object
  extended by com.metaparadigm.jsonrpc.JSONSerializer
All Implemented Interfaces:
java.io.Serializable

public class JSONSerializer
extends java.lang.Object
implements java.io.Serializable

This class is the public entry point to the serialization code and provides methods for marshalling Java objects into JSON objects and unmarshalling JSON objects into Java objects.

See Also:
Serialized Form

Constructor Summary
JSONSerializer()
           
 
Method Summary
 java.lang.Object fromJSON(java.lang.String s)
           
 boolean getMarshallClassHints()
          Should serializers defined in this object include the fully qualified class name of objects being serialized? This can be helpful when unmarshalling, though if not needed can be left out in favor of increased performance and smaller size of marshalled String.
 boolean getMarshallNullAttributes()
          Returns true if attributes will null values should still be included in the serialized JSON object.
 boolean isDebug()
           
 java.lang.Object marshall(SerializerState state, java.lang.Object o)
           
 void registerDefaultSerializers()
           
 void registerSerializer(Serializer s)
           
 void setDebug(boolean debug)
           
 void setMarshallClassHints(boolean marshallClassHints)
          Should serializers defined in this object include the fully qualified class name of objects being serialized? This can be helpful when unmarshalling, though if not needed can be left out in favor of increased performance and smaller size of marshalled String.
 void setMarshallNullAttributes(boolean marshallNullAttributes)
          Returns true if attributes will null values should still be included in the serialized JSON object.
 java.lang.String toJSON(java.lang.Object o)
           
 ObjectMatch tryUnmarshall(SerializerState state, java.lang.Class clazz, java.lang.Object json)
           
 java.lang.Object unmarshall(SerializerState state, java.lang.Class clazz, java.lang.Object json)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONSerializer

public JSONSerializer()
Method Detail

fromJSON

public java.lang.Object fromJSON(java.lang.String s)
                          throws UnmarshallException
Throws:
UnmarshallException

getMarshallClassHints

public boolean getMarshallClassHints()
Should serializers defined in this object include the fully qualified class name of objects being serialized? This can be helpful when unmarshalling, though if not needed can be left out in favor of increased performance and smaller size of marshalled String. Default is true.

Returns:
whether Java Class hints are included in the serialised JSON objects

getMarshallNullAttributes

public boolean getMarshallNullAttributes()
Returns true if attributes will null values should still be included in the serialized JSON object. Defaults to true. Set to false for performance gains and small JSON serialized size. Useful because null and undefined for JSON object attributes is virtually the same thing.

Returns:
boolean value as to whether null attributes will be in the serialized JSON objects

isDebug

public boolean isDebug()

marshall

public java.lang.Object marshall(SerializerState state,
                                 java.lang.Object o)
                          throws MarshallException
Throws:
MarshallException

registerDefaultSerializers

public void registerDefaultSerializers()
                                throws java.lang.Exception
Throws:
java.lang.Exception

registerSerializer

public void registerSerializer(Serializer s)
                        throws java.lang.Exception
Throws:
java.lang.Exception

setDebug

public void setDebug(boolean debug)

setMarshallClassHints

public void setMarshallClassHints(boolean marshallClassHints)
Should serializers defined in this object include the fully qualified class name of objects being serialized? This can be helpful when unmarshalling, though if not needed can be left out in favor of increased performance and smaller size of marshalled String. Default is true.

Parameters:
marshallClassHints - flag to enable/disable inclusion of Java class hints in the serialized JSON objects

setMarshallNullAttributes

public void setMarshallNullAttributes(boolean marshallNullAttributes)
Returns true if attributes will null values should still be included in the serialized JSON object. Defaults to true. Set to false for performance gains and small JSON serialized size. Useful because null and undefined for JSON object attributes is virtually the same thing.

Parameters:
marshallNullAttributes - flag to enable/disable marshalling of null attributes in the serialized JSON objects

toJSON

public java.lang.String toJSON(java.lang.Object o)
                        throws MarshallException
Throws:
MarshallException

tryUnmarshall

public ObjectMatch tryUnmarshall(SerializerState state,
                                 java.lang.Class clazz,
                                 java.lang.Object json)
                          throws UnmarshallException
Throws:
UnmarshallException

unmarshall

public java.lang.Object unmarshall(SerializerState state,
                                   java.lang.Class clazz,
                                   java.lang.Object json)
                            throws UnmarshallException
Throws:
UnmarshallException


Copyright © 2005 Metaparadigm Pte Ltd.