Interface OutboxEventSerializer

  • All Implemented Interfaces:

    
    public interface OutboxEventSerializer
    
                        

    Abstraction for serializing and deserializing outbox event payloads.

    This interface defines the contract for converting domain events to/from a storable format. Implementations are responsible for:

    • Converting event objects to string representation (JSON, XML, etc.)

    • Converting string representation back to typed event objects

    • Handling serialization errors gracefully

    The serialized format is stored in the outbox database as the event payload, which is later retrieved and deserialized during event processing.

    Default Implementation: The framework provides a Jackson-based implementation (JacksonEventOutboxSerializer) that uses Jackson's ObjectMapper for JSON serialization/deserialization.

    Custom Implementations: Users can provide custom implementations to support different serialization formats (e.g., Protocol Buffers, MessagePack, etc.) by implementing this interface and registering the bean in their Spring configuration.

    Since:

    0.3.0

    Author:

    Roland Beisel

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      abstract String serialize(Object outboxEvent) Serializes an event object to a string representation.
      abstract <T extends Any> T deserialize(String serialized, Class<T> type) Deserializes a string representation back to a typed event object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • serialize

         abstract String serialize(Object outboxEvent)

        Serializes an event object to a string representation.

        The serialized format is stored in the outbox database and must be deserializable back to the original event type using the deserialize method.

        Parameters:
        outboxEvent - The event object to serialize
        Returns:

        Serialized representation of the event (typically JSON)

      • deserialize

         abstract <T extends Any> T deserialize(String serialized, Class<T> type)

        Deserializes a string representation back to a typed event object.

        The provided type information is used to determine the target class for deserialization. This ensures type safety when reconstructing event objects from the outbox database.

        Parameters:
        serialized - The serialized event data (typically JSON)
        type - The target class to deserialize into
        Returns:

        The deserialized event object of type T