Skip to main content
Version: 1.10.x

Payload Serialization

Records are serialized before storage and deserialized during processing. The library provides flexible serialization through the OutboxPayloadSerializer interface.

The fully qualified payload class name is persisted with every record. Package or class renames and breaking payload changes therefore require a compatibility rollout. See Rolling Deployments.

Jackson Module (Default)​

The namastack-outbox-jackson module is the default for JSON serialization, leveraging Jackson 3.x. It is automatically included when you use either the JDBC or JPA starter.

Supported Features:

  • JSON serialization/deserialization
  • Custom Jackson modules and mixins
  • Standard Jackson configuration via spring.jackson.* properties

Example Jackson Configuration:

spring:
jackson:
default-property-inclusion: NON_NULL
serialization:
write-dates-as-timestamps: false
indent-output: true
deserialization:
fail-on-unknown-properties: false

OutboxPayloadSerializer Interface​

interface OutboxPayloadSerializer {
fun serialize(payload: Any): String
fun <T> deserialize(data: String, targetType: Class<T>): T
}

Custom Serializer Implementation​

@Configuration
class OutboxSerializationConfig {
@Bean
fun protobufSerializer(): OutboxPayloadSerializer {
return object : OutboxPayloadSerializer {
override fun serialize(payload: Any): String {
// Implement Protobuf serialization
require(payload is Message) { "Payload must be Protobuf Message" }
return Base64.encoder.encodeToString(payload.toByteArray())
}
override fun <T> deserialize(data: String, targetType: Class<T>): T {
// Implement Protobuf deserialization
val bytes = Base64.decoder.decode(data)
val method = targetType.getMethod("parseFrom", ByteArray::class.java)
@Suppress("UNCHECKED_CAST")
return method.invoke(null, bytes) as T
}
}
}
}

Important: When you provide a custom serializer as a Spring bean, it automatically replaces the default Jackson serializer.

The built-in repositories resolve the persisted root payload class before calling deserialize. They also recognize a JVM LinkageError propagated by the serializer when a referenced payload type is unavailable. Errors specific to a serialization library have no common meaning and are handled as ordinary deserialization failures. See Rolling Deployments for the resulting compatibility behavior.