Class MarshallerService
- All Implemented Interfaces:
IMarshallerService
This implementation adds type information to encoded JSON strings and will use it when deserializing.
Type information is typically obtained from the attribute definition of the class in which it is defined,
or the class passed to the marshal(Object anyObject, boolean useRegisteredClassTyping).
This is not useful when working with interface, abstract base class or Object definitions, as it could be a number of different classes. In these situations, the key "@type" is used to indicate a string for class identification.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault public constructor - for testing purposes only! Otherwise use OSGi to get the service.MarshallerService(List<IClassRegistry> extraRegistries, List<IMarshaller> marshallers) Constructor for testing to allow IMarshaller(s) or IClassRegistry('s) to be injected.MarshallerService(IClassRegistry... extraRegistries) Constructor for testing to allow IClassRegistry('s) to be injected.MarshallerService(IMarshaller... marshallers) Constructor for testing to allow IMarshaller(s) to be injected. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true if this Object has a mix-in class (for ROIs for instance)Serialize the given object to a JSON stringThis marshal gives the option of turning off the class registry id information in the serialization.<U> UDeserialize the given JSON string as an instance of the given class
-
Constructor Details
-
MarshallerService
public MarshallerService()Default public constructor - for testing purposes only! Otherwise use OSGi to get the service. -
MarshallerService
Constructor for testing to allow IClassRegistry('s) to be injected.- Parameters:
extraRegistries-
-
MarshallerService
Constructor for testing to allow IMarshaller(s) to be injected.- Parameters:
marshallers-
-
MarshallerService
Constructor for testing to allow IMarshaller(s) or IClassRegistry('s) to be injected.- Parameters:
extraRegistries-marshallers-
-
-
Method Details
-
marshal
Serialize the given object to a JSON stringObjects to be marshalled with this implementation should have no-arg constructors, and getters and setters for their fields. Primitive and collection types (arrays, Collections and Maps) should work correctly. More complicated types (generics other than collections, inner classes etc) might or might not work properly.
- Specified by:
marshalin interfaceIMarshallerService- Parameters:
anyObject- the object to be serialized- Returns:
- the JSON string representing the object
- Throws:
Exception- if the object cannot be marshalled correctly
-
marshal
Description copied from interface:IMarshallerServiceThis marshal gives the option of turning off the class registry id information in the serialization. If you are not using interfaces (the norm) then this information is not needed because the types are static.- Specified by:
marshalin interfaceIMarshallerService- Parameters:
anyObject-useRegisteredClassTyping-- Returns:
- the JSON string representing the object
- Throws:
Exception
-
unmarshal
Deserialize the given JSON string as an instance of the given classThis method will try to find the correct classes for deserialization from the class id, if type not given.
- Specified by:
unmarshalin interfaceIMarshallerService- Parameters:
string- the JSON string to be deserializedbeanClass- the expected class of the deserialized object- Returns:
- the deserialized object
- Throws:
Exception- if the object cannot be unmarshalled correctly
-
isObjMixInSupported
Description copied from interface:IMarshallerServiceReturns true if this Object has a mix-in class (for ROIs for instance)- Specified by:
isObjMixInSupportedin interfaceIMarshallerService- Parameters:
roi-- Returns:
- boolean
-