Class DelegatingMessageConverter

java.lang.Object
org.axonframework.messaging.core.conversion.DelegatingMessageConverter
All Implemented Interfaces:
DescribableComponent, Converter, MessageConverter

public class DelegatingMessageConverter extends Object implements MessageConverter
A MessageConverter implementation delegating conversion operations to a Converter.

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

Since:
5.0.0
Author:
Steven van Beelen
  • Constructor Details

    • DelegatingMessageConverter

      public DelegatingMessageConverter(@Nonnull Converter delegate)
      Constructs a DelegatingMessageConverter, 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 <M extends Message, T> T convertPayload(@Nonnull M message, @Nonnull Type targetType)
      Description copied from interface: MessageConverter
      Converts the given message's payload into a payload of the given targetType.
      Specified by:
      convertPayload in interface MessageConverter
      Type Parameters:
      M - The type of Message to convert the payload for.
      T - The target data type.
      Parameters:
      message - The Message to convert the payload for.
      targetType - The type to convert the payload into.
      Returns:
      A converted version of the given Message's payload into the given targetType.
    • convertMessage

      @Nonnull public <M extends Message> M convertMessage(@Nonnull M message, @Nonnull Type targetType)
      Description copied from interface: MessageConverter
      Converts the given message's payload to the given targetType, returning a new Message with the converted payload.
      Specified by:
      convertMessage in interface MessageConverter
      Type Parameters:
      M - The type of Message to convert and return.
      Parameters:
      message - The Message to convert the payload for.
      targetType - The type to convert the payload into.
      Returns:
      A new Message containing the converted version of the given message'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 Converter delegate()
      Returns the delegate Converter this MessageConverter delegates to.

      Useful to construct other instances with the exact same Converter.

      Returns:
      The Converter this MessageConverter delegates to.