SerializationService

Object serialization is the process of converting objects into a stream of bytes and, deserialization, the reverse process of creating objects from a stream of bytes. You can serialize and deserialize outputted bytes using the SerializationService, which can be injected into flows and services.

Examples

  • Kotlin
class SerializationExampleFlow : Flow<Unit> {

  @CordaInject
  private lateinit var serializationService: SerializationService

  @Suspendable
  override fun call() {
    // Serialize an object
    val serialized: SerializedBytes<String> = serializationService.serialize("string to serialize")
    // Deserialize the serialized bytes
    val deserialized: String = serializationService.deserialize(serialized, String::class.java)
  }
}
  • Java
public class SerializationExampleFlow implements Flow<Void> {

  @CordaInject
  private SerializationService serializationService;

  @Override
  @Suspendable
  public Void call() {
    // Serialize an object
    SerializedBytes<String> serialized = serializationService.serialize("string to serialize");
    // Deserialize the serialized bytes
    String deserialized = serializationService.deserialize(serialized, String.class);
    return null;
  }
}

If you are a Kotlin developer, you also have access to some inline functions:

// Serialize an object
val serialized: SerializedBytes<String> = serializationService.serialize("string to serialize")
// Deserialize the serialized bytes
// The class doesn't have to be included directly when using the inline version
val deserialized: String = serializationService.deserialize(serialized)

Was this page helpful?

Thanks for your feedback!

Chat with us

Chat with us on our #docs channel on slack. You can also join a lot of other slack channels there and have access to 1-on-1 communication with members of the R3 team and the online community.

Propose documentation improvements directly

Help us to improve the docs by contributing directly. It's simple - just fork this repository and raise a PR of your own - R3's Technical Writers will review it and apply the relevant suggestions.

We're sorry this page wasn't helpful. Let us know how we can make it better!

Chat with us

Chat with us on our #docs channel on slack. You can also join a lot of other slack channels there and have access to 1-on-1 communication with members of the R3 team and the online community.

Create an issue

Create a new GitHub issue in this repository - submit technical feedback, draw attention to a potential documentation bug, or share ideas for improvement and general feedback.

Propose documentation improvements directly

Help us to improve the docs by contributing directly. It's simple - just fork this repository and raise a PR of your own - R3's Technical Writers will review it and apply the relevant suggestions.