SerializationFactory
Keywords: net.corda.core.serialization.SerializationFactory class
Date: 2023-09-18

net.corda.core.serialization

## Class SerializationFactory

- net.corda.core.serialization.SerializationFactory

-     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.

- - ### Field Detail

    - #### Companion

          public static net.corda.core.serialization.SerializationFactory.Companion Companion

  - ### Constructor Detail

    - #### SerializationFactory

          public SerializationFactory()

      An abstraction for serializing and deserializing objects, with support for versioning of the wire format via a header / prefix in the bytes.

  - ### Method Detail

    - #### deserialize

          @NotNull
          public <T> T deserialize(@NotNull
                                            ByteSequence byteSequence,
                                            @NotNull
                                            java.lang.Class<T> clazz,
                                            @NotNull
                                            SerializationContext context)

      Deserialize the bytes in to an object, using the prefixed bytes to determine the format.

      Parameters:
        `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.

    - #### deserializeWithCompatibleContext

          @NotNull
          public <T> ObjectWithCompatibleContext<T> deserializeWithCompatibleContext(@NotNull
                                                                                              ByteSequence byteSequence,
                                                                                              @NotNull
                                                                                              java.lang.Class<T> clazz,
                                                                                              @NotNull
                                                                                              SerializationContext context)

      Deserialize the bytes in to an object, using the prefixed bytes to determine the format.

      Parameters:
        `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.
      Returns:
        deserialized object along with `interface SerializationContext` to identify encoding used.

    - #### serialize

          @NotNull
          public <T> SerializedBytes<T> serialize(@NotNull
                                                           T obj,
                                                           @NotNull
                                                           SerializationContext context)

      Serialize an object to bytes using the preferred serialization format version from the context.

      Parameters:
        `obj` - The object to be serialized.
        `context` - A context that configures various parameters to serialization, including the serialization format version.

    - #### getCurrentContext

          @Nullable
          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.

    - #### getDefaultContext

          @NotNull
          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 `currentContext`).

      See Also:
        `currentContext`

    - #### withCurrentContext

          public <T> T withCurrentContext(@Nullable
                                          SerializationContext context,
                                          @NotNull
                                          kotlin.jvm.functions.Function0<? extends T> block)

      Change the current context inside the block to that supplied.

    - #### asCurrent

          public <T> T asCurrent(@NotNull
                                 kotlin.jvm.functions.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.