public abstract class AbstractObjectSerializer extends Object implements ObjectSerializer, MuleContextAware
ObjectSerializer
This class implements all the base behavioral contract allowing its extensions to
only care about the actual serialization/deserialization part.Modifier and Type | Field and Description |
---|---|
protected MuleContext |
muleContext |
Constructor and Description |
---|
AbstractObjectSerializer() |
Modifier and Type | Method and Description |
---|---|
<T> T |
deserialize(byte[] bytes)
Deserializes the given bytes.
|
<T> T |
deserialize(byte[] bytes,
ClassLoader classLoader)
Deserializes the given bytes.
|
<T> T |
deserialize(InputStream inputStream)
Deserializes the given stream of bytes.
|
<T> T |
deserialize(InputStream inputStream,
ClassLoader classLoader)
Deserializes the given stream of bytes.
|
protected abstract <T> T |
doDeserialize(InputStream inputStream,
ClassLoader classLoader)
Deserializes the given
inputStream using the provided classLoader . |
protected abstract byte[] |
doSerialize(Object object)
Serializes the given object.
|
protected <T> T |
postInitialize(T object) |
byte[] |
serialize(Object object)
Serializes the given object into a an array of
byte s |
void |
serialize(Object object,
OutputStream out)
Serializes the given object and writes the result into
out |
void |
setMuleContext(MuleContext context) |
protected MuleContext muleContext
protected abstract byte[] doSerialize(Object object) throws Exception
object
- the object to be serializedException
- any exception thrown. Base class will handle accordinglyprotected abstract <T> T doDeserialize(InputStream inputStream, ClassLoader classLoader) throws Exception
inputStream
using the provided classLoader
.
No need to worry about error handling or deserialization post initialization. Base class
does all of that automaticallyinputStream
- an open InputStream
, not to be explicitly closed in this methodclassLoader
- a ClassLoader
Exception
public byte[] serialize(Object object) throws SerializationException
byte
sserialize
in interface ObjectSerializer
object
- the object to be serialized. Might be null
byte
IllegalArgumentException
- if object is not a Serializable
SerializationException
- in case of unexpected exceptionpublic void serialize(Object object, OutputStream out) throws SerializationException
out
serialize
in interface ObjectSerializer
object
- the object to be serialized. Might be null
out
- an OutputStream
where the result will be writtenIllegalArgumentException
- if object is not a Serializable
SerializationException
- in case of unexpected exceptionpublic <T> T deserialize(byte[] bytes) throws SerializationException
DeserializationPostInitialisable
then this serializer will be responsible for properly initializing
the object before returning it.
Implementation will choose the ClassLoader
to use for deserialization.deserialize
in interface ObjectSerializer
bytes
- an array of byte that an original object was serialized intoSerializationException
- in case of unexpected exceptionpublic <T> T deserialize(byte[] bytes, ClassLoader classLoader) throws SerializationException
DeserializationPostInitialisable
then this serializer will be responsible for properly initializing
the object before returning it.deserialize
in interface ObjectSerializer
bytes
- an array of byte that an original object was serialized intoclassLoader
- the ClassLoader
to deserialize withSerializationException
- in case of unexpected exceptionpublic <T> T deserialize(InputStream inputStream) throws SerializationException
ClassLoader
to use for deserialization.
Even if deserialization fails, this method will close the
inputStream
If the obtained object implements DeserializationPostInitialisable
then this serializer will be responsible for properly initializing
the object before returning it.deserialize
in interface ObjectSerializer
inputStream
- a stream of bytes that an original object was serialized intoSerializationException
- in case of unexpected exceptionpublic <T> T deserialize(InputStream inputStream, ClassLoader classLoader) throws SerializationException
inputStream
If the obtained object implements DeserializationPostInitialisable
then this serializer will be responsible for properly initializing
the object before returning it.deserialize
in interface ObjectSerializer
inputStream
- a stream of bytes that an original object was serialized intoclassLoader
- the ClassLoader
to deserialize withSerializationException
- in case of unexpected exceptionprotected <T> T postInitialize(T object) throws SerializationException
SerializationException
public final void setMuleContext(MuleContext context)
setMuleContext
in interface MuleContextAware
Copyright © 2003–2015 MuleSoft, Inc.. All rights reserved.