Class PassThroughConverter

java.lang.Object
org.axonframework.conversion.PassThroughConverter
All Implemented Interfaces:
DescribableComponent, Converter

public final class PassThroughConverter extends Object implements Converter
A Converter implementation that only "passes through" input object if the sourceType and targetType are the identical.

As such, no conversion is performed by this Converter! The Converter.canConvert(Class, Class) operation will only return true whenever both types are identical. Furthermore, both Converter.convert(Object, Class) and convert(Object, Type) will expect identical typing too, otherwise resulting in an IllegalArgumentException.

As such, this Converter is only useful when conversion is not necessary (e.g. during testing) for the component at hand.

Since:
5.0.0
Author:
Mateusz Nowak
  • Field Details

    • INSTANCE

      public static final PassThroughConverter INSTANCE
      The single instance of the PassThroughConverter.
  • 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.
    • 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.