Class DelegatingEventConverter

java.lang.Object
org.axonframework.messaging.eventhandling.conversion.DelegatingEventConverter
All Implemented Interfaces:
DescribableComponent, Converter, EventConverter

public class DelegatingEventConverter extends Object implements EventConverter
An EventConverter implementation delegating conversion operations to a MessageConverter.

Useful to ensure callers of this component only convert EventMessage implementations.

Since:
5.0.0
Author:
Steven van Beelen
  • Constructor Details

    • DelegatingEventConverter

      public DelegatingEventConverter(@Nonnull Converter converter)
      Constructs a DelegatingEventConverter, delegating operations to a DelegatingMessageConverter build with the given converter.
      Parameters:
      converter - The converter to construct a DelegatingMessageConverter with to delegate all conversion operations to.
    • DelegatingEventConverter

      public DelegatingEventConverter(@Nonnull MessageConverter delegate)
      Constructs a DelegatingEventConverter, delegating operations to the given converter.
      Parameters:
      delegate - The converter to delegate all conversion operations to.
  • Method Details

    • canConvert

      public boolean canConvert(@Nonnull Type sourceType, @Nonnull Type targetType)
      Description copied from interface: Converter
      Indicates whether this Converter is capable of converting the given sourceType to the targetType.
      Specified by:
      canConvert in interface Converter
      Parameters:
      sourceType - The type of data to convert from.
      targetType - The type of data to convert to.
      Returns:
      true if conversion is possible, false otherwise.
    • convert

      @Nullable public <T> T convert(@Nullable Object input, @Nonnull Type targetType)
      Description copied from interface: Converter
      Converts the given input object into an object of the given targetType.
      Specified by:
      convert in interface Converter
      Type Parameters:
      T - The target data type.
      Parameters:
      input - The value to convert.
      targetType - The type to convert the given input into.
      Returns:
      A converted version of the given input into the given targetType.
    • convertPayload

      @Nullable public <E extends EventMessage, T> T convertPayload(@Nonnull E event, @Nonnull Type targetType)
      Description copied from interface: EventConverter
      Converts the given event's payload into a payload of the given targetType.
      Specified by:
      convertPayload in interface EventConverter
      Type Parameters:
      E - The type of EventMessage to convert the payload for.
      T - The target data type.
      Parameters:
      event - The EventMessage to convert the payload for.
      targetType - The type to convert the payload into.
      Returns:
      A converted version of the given EventMessage's payload into the given targetType.
    • convertEvent

      @Nonnull public <E extends EventMessage> E convertEvent(@Nonnull E event, @Nonnull Type targetType)
      Description copied from interface: EventConverter
      Converts the given event's payload to the given targetType, returning a new EventMessage with the converted payload.
      Specified by:
      convertEvent in interface EventConverter
      Type Parameters:
      E - The type of EventMessage to convert and return.
      Parameters:
      event - The EventMessage to convert the payload for.
      targetType - The type to convert the payload into.
      Returns:
      A new EventMessage containing the converted version of the given event's payload into the given targetType.
    • describeTo

      public void describeTo(@Nonnull ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.

      Best Practices: As a general rule, all relevant fields of a DescribableComponent implementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing the describeTo method, who should focus on providing information that is useful for understanding the component's configuration and state.

      Example implementation:

       public void describeTo(ComponentDescriptor descriptor) {
           descriptor.describeProperty("name", this.name);
           descriptor.describeProperty("enabled", this.enabled);
           descriptor.describeProperty("configuration", this.configuration); // A nested component
           descriptor.describeProperty("handlers", this.eventHandlers);      // A collection
       }
       
      Specified by:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.
    • delegate

      @Internal public MessageConverter delegate()
      Returns the MessageConverter this EventConverter delegates to.

      Useful to construct other instances with the exact same Converter.

      Returns:
      The MessageConverter this EventConverter delegates to.