org.openmrs.api
Interface SerializationService

All Superinterfaces:
OpenmrsService
All Known Implementing Classes:
SerializationServiceImpl

@Transactional
public interface SerializationService
extends OpenmrsService

Contains methods for retrieving registered Serializer instances, and for persisting/retrieving/deleting objects using serialization

Since:
1.5

Method Summary
<T> T
deserialize(java.lang.String serializedObject, java.lang.Class<? extends T> objectClass, java.lang.Class<? extends OpenmrsSerializer> serializerClass)
          Deserialize the given string into a full object using the given OpenmrsSerializer class
 OpenmrsSerializer getDefaultSerializer()
          Returns the default serializer configured for the system.
 OpenmrsSerializer getSerializer(java.lang.Class<? extends OpenmrsSerializer> serializationClass)
          Returns the serializer that matches the passed class, or null if no such serializer exists.
 java.util.List<? extends OpenmrsSerializer> getSerializers()
          Gets the list of OpenmrsSerializers that have been registered with this service.
 java.lang.String serialize(java.lang.Object o, java.lang.Class<? extends OpenmrsSerializer> clazz)
          Serialize the passed object into an identifying string that can be retrieved later using the passed OpenmrsSerializer class
 
Methods inherited from interface org.openmrs.api.OpenmrsService
onShutdown, onStartup
 

Method Detail

getDefaultSerializer

OpenmrsSerializer getDefaultSerializer()
Returns the default serializer configured for the system. This enables a user to serialize objects without needing to know the underlying serialization implementation class.

Returns:
OpenmrsSerializer the default configured serializer
Expected behavior:
return a serializer

getSerializer

OpenmrsSerializer getSerializer(java.lang.Class<? extends OpenmrsSerializer> serializationClass)
Returns the serializer that matches the passed class, or null if no such serializer exists.

Parameters:
serializationClass - - the serialization class to retrieve
Returns:
OpenmrsSerializer that matches the passed class
Expected behavior:
return a serializer of the given class

serialize

java.lang.String serialize(java.lang.Object o,
                           java.lang.Class<? extends OpenmrsSerializer> clazz)
                           throws SerializationException
Serialize the passed object into an identifying string that can be retrieved later using the passed OpenmrsSerializer class

Parameters:
o - - the object to serialize
clazz - - the OpenmrsSerializer class to use for serialization
Returns:
String representing this object
Throws:
SerializationException
Expected behavior:
Serialize And Deserialize Correctly, Serialize And Deserialize Hibernate Objects Correctly

deserialize

<T> T deserialize(java.lang.String serializedObject,
                  java.lang.Class<? extends T> objectClass,
                  java.lang.Class<? extends OpenmrsSerializer> serializerClass)
              throws SerializationException
Deserialize the given string into a full object using the given OpenmrsSerializer class

Parameters:
serializedObject - - String to deserialize into an Object
objectClass - - The class to deserialize the Object into
serializerClass - - The OpenmrsSerializer class to use to perform the deserialization
Returns:
hydrated object of the appropriate type
Throws:
SerializationException

getSerializers

java.util.List<? extends OpenmrsSerializer> getSerializers()
Gets the list of OpenmrsSerializers that have been registered with this service.

Modules are able to add more serializers by adding this in their moduleApplicationContext. e.g.:
        <bean parent="serializationServiceTarget">
                <property name="serializers">
                <list>
                        <ref bean="xstreamSerializer"/>
                </list>
                </property>
  </bean>
  <bean id="xstreamSerializer" class="org.openmrs.module.serialization.xstream.XStreamSerializer"/>
 

Returns:
list of serializers currently loaded in openmrs

OpenMRS-1.7.x

Generated Apr 27 2012 10:06 PM. NOTE - these libraries are in active development and subject to change