com.metaparadigm.jsonrpc.serializer
Interface Serializer

All Superinterfaces:
java.io.Serializable
All Known Implementing Classes:
AbstractSerializer, ArraySerializer, BeanSerializer, BooleanSerializer, DateSerializer, DictionarySerializer, ListSerializer, MapSerializer, NumberSerializer, PrimitiveSerializer, RawJSONArraySerializer, RawJSONObjectSerializer, ReferenceSerializer, SetSerializer, StringSerializer

public interface Serializer
extends java.io.Serializable

Interface to be implemented by custom serializer objects that convert to and from Java objects and JSON objects.


Method Summary
 boolean canSerialize(java.lang.Class clazz, java.lang.Class jsonClazz)
          Determine if the given java,json class pair can be handled by this serializer.
 java.lang.Class[] getJSONClasses()
          Get the json java classes that this Serializer is able to serialize from json into java and deserialize into json from java.
 java.lang.Class[] getSerializableClasses()
          Get the java classes that this Serializer is able to serialize from java into json and deserialize into java from json.
 java.lang.Object marshall(SerializerState state, java.lang.Object o)
          Marshall a java object into an equivalent json object.
 void setOwner(JSONSerializer ser)
          Set the owning JSONSerializer of this Serializer instance.
 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)
          Unmarshall json into an equivalent java object.
 

Method Detail

canSerialize

boolean canSerialize(java.lang.Class clazz,
                     java.lang.Class jsonClazz)
Determine if the given java,json class pair can be handled by this serializer. Both for serialzing from java => json and deserializing from json => java.

Parameters:
clazz - java Class type.
jsonClazz - json Class wrapper type.
Returns:
true if this serializer can serialize/deserialize the given pair.

getJSONClasses

java.lang.Class[] getJSONClasses()
Get the json java classes that this Serializer is able to serialize from json into java and deserialize into json from java. These will typically be primitive class type wrappers or JSONObject, JSONArray.

Returns:
json side java classes that can be serialized/deserialized by this serializer.

getSerializableClasses

java.lang.Class[] getSerializableClasses()
Get the java classes that this Serializer is able to serialize from java into json and deserialize into java from json.

Returns:
java side classes that can be serialized/deserialized by this serializer.

marshall

java.lang.Object marshall(SerializerState state,
                          java.lang.Object o)
                          throws MarshallException
Marshall a java object into an equivalent json object.

Parameters:
state - can be used to hold state while unmarshalling through recursive levels.
o - java object to marhsall into json.
Returns:
that JSONObject or JSONArray that contains the json representation of the java object that was marshalled.
Throws:
MarshallException - if there is a problem marshalling java to json.

setOwner

void setOwner(JSONSerializer ser)
Set the owning JSONSerializer of this Serializer instance.

Parameters:
ser - the owning JSONSerializer of this Serializer instance.

tryUnmarshall

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

unmarshall

java.lang.Object unmarshall(SerializerState state,
                            java.lang.Class clazz,
                            java.lang.Object json)
                            throws UnmarshallException
Unmarshall json into an equivalent java object.

Parameters:
state - can be used to hold state while unmarshalling through recursive levels.
clazz - optional java class to unmarshall to.
json - JSONObject or JSONArray that contains the json to unmarshall.
Returns:
the java object representing the json that was unmarshalled.
Throws:
UnmarshallException - if there is a problem unmarshalling json to java.


Copyright © 2005 Metaparadigm Pte Ltd.