Class AvroConverter

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

public class AvroConverter extends Object implements Converter
Converter providing support for Apache Avro, using Single Object Encoded binary encoding.

This converter is intended to work for classes, representing messages specified by Avro Schema. It is limited to conversions specifying Class as a target type (and can not work on pure Type) definitions.

The conversion is delegated to the AvroConverterStrategy implementations. By default, the SpecificRecordBaseConverterStrategy is provided and configured, to support Java classes generated by Avro Maven plugin (delivered by Avro Java distribution). The AvroConverterConfiguration allows to register further strategies. At least one strategy has to be configured for this converter to work.

Since:
4.11.0
Author:
Simon Zambrovski, Jan Galinski
  • Constructor Details

    • AvroConverter

      public AvroConverter(@Nonnull org.apache.avro.message.SchemaStore schemaStore, @Nonnull UnaryOperator<AvroConverterConfiguration> configurationOverride)
      Creates the converter instance.
      Parameters:
      schemaStore - schema store to use.
      configurationOverride - configuration customizer.
    • AvroConverter

      @Internal public AvroConverter(@Nonnull org.apache.avro.message.SchemaStore schemaStore, @Nonnull UnaryOperator<AvroConverterConfiguration> configurationOverride, @Nonnull ChainingContentTypeConverter chainingTypeConverter)
      Creates the converter instance.
      Parameters:
      schemaStore - schema store to use.
      configurationOverride - configuration customizer.
      chainingTypeConverter - chaining type converter.
  • 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.