Class SpecificRecordBaseConverterStrategy

java.lang.Object
org.axonframework.conversion.avro.SpecificRecordBaseConverterStrategy
All Implemented Interfaces:
Predicate<Class<?>>, DescribableComponent, AvroConverterStrategy

public class SpecificRecordBaseConverterStrategy extends Object implements AvroConverterStrategy
Avro strategy responsible for operations on SpecificRecordBase as a superclass of all objects you are working on.
Since:
4.11.0
Author:
Simon Zambrovski, Jan Galinski
  • Constructor Details

    • SpecificRecordBaseConverterStrategy

      public SpecificRecordBaseConverterStrategy(@Nonnull org.apache.avro.message.SchemaStore schemaStore, @Nonnull SchemaIncompatibilityChecker schemaIncompatibilityChecker)
      Constructs avro conversion strategy supporting conversion and deserialization of Java Avro classes extending SpecificRecordBase.
      Parameters:
      schemaStore - schema store to resolve schema from fingerprint.
      schemaIncompatibilityChecker - stateful utility to perform compatibility checks.
  • Method Details

    • convertToSingleObjectEncoded

      @Nonnull public byte[] convertToSingleObjectEncoded(@Nonnull Object object)
      Description copied from interface: AvroConverterStrategy
      Converts the given object to byte array using Avro single-object-encoding.
      Specified by:
      convertToSingleObjectEncoded in interface AvroConverterStrategy
      Parameters:
      object - The object to convert.
      Returns:
      The byte array containing Avro Single Object Encoded bytes.
    • convertFromSingleObjectEncoded

      @Nonnull public <T> T convertFromSingleObjectEncoded(@Nonnull byte[] bytes, @Nonnull Class<T> readerType)
      Description copied from interface: AvroConverterStrategy
      Converts from single object encoded byte array.
      Specified by:
      convertFromSingleObjectEncoded in interface AvroConverterStrategy
      Type Parameters:
      T - The payload type to convert to.
      Parameters:
      bytes - An array containing single-object-encoded bytes.
      readerType - The class of resulting object.
      Returns:
      The deserialized object.
    • convertFromGenericRecord

      @Nonnull public <T> T convertFromGenericRecord(@Nonnull org.apache.avro.generic.GenericRecord genericRecord, @Nonnull Class<T> readerType)
      Description copied from interface: AvroConverterStrategy
      Converts from Apache Avro generic record (intermediate representation).
      Specified by:
      convertFromGenericRecord in interface AvroConverterStrategy
      Type Parameters:
      T - The payload type to convert to.
      Parameters:
      genericRecord - The input object containing the generic record.
      readerType - The class of resulting object.
      Returns:
      deserialized object.
    • test

      public boolean test(@Nonnull Class<?> payloadType)
      Description copied from interface: AvroConverterStrategy
      Determines if this strategy supports given payloadType. This means that we have either a SpecificRecordBase generated from a schema using apache-avro-maven-plugin or a kotlinx serializable class, written using avro4k.
      Specified by:
      test in interface AvroConverterStrategy
      Specified by:
      test in interface Predicate<Class<?>>
      Parameters:
      payloadType - The payload type of object to de-/serialize, for example BankAccountCreated.class.
      Returns:
      true if type is supported by this strategy, false otherwise.
    • applyStrategyConfiguration

      public void applyStrategyConfiguration(@Nonnull AvroConverterStrategyConfiguration avroConverterConfiguration)
      Description copied from interface: AvroConverterStrategy
      Sets the configuration for the strategy.

      This method is called during the construction of AvroConverter, passing the configuration to the strategy. The default implementation does nothing, but a strategy might use this method to set up internals.

      This method is intended to be implemented by the strategy, if it supports configuration options passed via AvroConverterStrategyConfiguration

      Specified by:
      applyStrategyConfiguration in interface AvroConverterStrategy
      Parameters:
      avroConverterConfiguration - configuration passed after construction.
    • 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.