com.sag.osami.contextstore.serialization.json
Class JSONSerializer

java.lang.Object
  extended by com.sag.osami.contextstore.serialization.json.JSONSerializer
All Implemented Interfaces:
ISerializationHandler

public class JSONSerializer
extends java.lang.Object
implements ISerializationHandler

This serializing utility class uses the Jackson JSON-processor library, which is insanely fast and equally easy to use.

Yet there are a few restrictions regarding the classes of the data to be serialized:

Apart from this, there is little which can be done incorrectly: Jackson handles Java's built-in types flawlessly, even when interface types as Map are used -- then, sensible default types are used during deserialization. Your classes don't have to implement the Serializable interface. Those kinds of data which are not particularly suited for JSON (e.g. huge byte[] arrays) are handled (space-)efficiently.

Please note, that Jackson is not embedded in this bundle but must be present as an own bundle. See the Jackson download page for officially packaged OSGi bundles. Both jackson-core and jackson-mapper are necessary.

OSGi notice: In order to be able to deserialize all kinds of data, this bundle uses a wildcard Dynamic-Import.


Constructor Summary
JSONSerializer()
           
 
Method Summary
 java.lang.Object deserialize(java.lang.String[] sobj)
          Deserializes the given data.
static org.codehaus.jackson.map.ObjectMapper getJSON()
          Returns the internally used instance of the Jackson ObjectMapper for re-use since creation of ObjectMappers can be considered as costly.
 java.lang.String[] serialize(java.lang.Object obj)
          Serializes the given object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONSerializer

public JSONSerializer()
Method Detail

getJSON

public static org.codehaus.jackson.map.ObjectMapper getJSON()
Returns the internally used instance of the Jackson ObjectMapper for re-use since creation of ObjectMappers can be considered as costly.

Returns:
the internally used ObjectMapper instance

serialize

public java.lang.String[] serialize(java.lang.Object obj)
Description copied from interface: ISerializationHandler
Serializes the given object. Should return null when obj is null. Must be thread-safe.

Specified by:
serialize in interface ISerializationHandler
Parameters:
obj - object to be serialized

deserialize

public java.lang.Object deserialize(java.lang.String[] sobj)
Description copied from interface: ISerializationHandler
Deserializes the given data. Should return null when sobj is null. Must be thread-safe.

Specified by:
deserialize in interface ISerializationHandler
Parameters:
sobj - the serialized data as returned by the ISerializationHandler.serialize(Object) method
Returns:
the deserialized object