public class SerializationFactory
An abstraction for serializing and deserializing objects, with support for versioning of the wire format via a header / prefix in the bytes.
Modifier and Type | Class and Description |
---|---|
static class |
SerializationFactory.Companion |
Modifier and Type | Field and Description |
---|---|
static SerializationFactory.Companion |
Companion |
Constructor and Description |
---|
SerializationFactory()
An abstraction for serializing and deserializing objects, with support for versioning of the wire format via
a header / prefix in the bytes.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
asCurrent(Function1<? super net.corda.core.serialization.SerializationFactory,? extends T> block)
Allow subclasses to temporarily mark themselves as the current factory for the current thread during serialization/deserialization.
Will restore the prior context on exiting the block.
|
<T> T |
deserialize(ByteSequence byteSequence,
java.lang.Class<T> clazz,
SerializationContext context)
Deserialize the bytes in to an object, using the prefixed bytes to determine the format.
|
<T> ObjectWithCompatibleContext<T> |
deserializeWithCompatibleContext(ByteSequence byteSequence,
java.lang.Class<T> clazz,
SerializationContext context)
Deserialize the bytes in to an object, using the prefixed bytes to determine the format.
|
SerializationContext |
getCurrentContext()
If there is a need to nest serialization/deserialization with a modified context during serialization or deserialization,
this will return the current context used to start serialization/deserialization.
|
SerializationContext |
getDefaultContext()
A context to use as a default if you do not require a specially configured context. It will be the current context
if the use is somehow nested (see
SerializationFactory.getCurrentContext ). |
<T> SerializedBytes<T> |
serialize(T obj,
SerializationContext context)
Serialize an object to bytes using the preferred serialization format version from the context.
|
<T> T |
withCurrentContext(SerializationContext context,
Function0<? extends T> block)
Change the current context inside the block to that supplied.
|
public static SerializationFactory.Companion Companion
public SerializationFactory()
An abstraction for serializing and deserializing objects, with support for versioning of the wire format via a header / prefix in the bytes.
public <T> T deserialize(ByteSequence byteSequence, java.lang.Class<T> clazz, SerializationContext context)
Deserialize the bytes in to an object, using the prefixed bytes to determine the format.
public <T> ObjectWithCompatibleContext<T> deserializeWithCompatibleContext(ByteSequence byteSequence, java.lang.Class<T> clazz, SerializationContext context)
Deserialize the bytes in to an object, using the prefixed bytes to determine the format.
byteSequence
- The bytes to deserialize, including a format header prefix.clazz
- The class or superclass or the object to be deserialized, or Any or Object if unknown.context
- A context that configures various parameters to deserialization.interface SerializationContext
to identify encoding used.public <T> SerializedBytes<T> serialize(T obj, SerializationContext context)
Serialize an object to bytes using the preferred serialization format version from the context.
obj
- The object to be serialized.context
- A context that configures various parameters to serialization, including the serialization format version.public SerializationContext getCurrentContext()
If there is a need to nest serialization/deserialization with a modified context during serialization or deserialization, this will return the current context used to start serialization/deserialization.
public SerializationContext getDefaultContext()
A context to use as a default if you do not require a specially configured context. It will be the current context
if the use is somehow nested (see SerializationFactory.getCurrentContext
).
SerializationFactory.getCurrentContext
public <T> T withCurrentContext(SerializationContext context, Function0<? extends T> block)
Change the current context inside the block to that supplied.
public <T> T asCurrent(Function1<? super net.corda.core.serialization.SerializationFactory,? extends T> block)
Allow subclasses to temporarily mark themselves as the current factory for the current thread during serialization/deserialization. Will restore the prior context on exiting the block.