Interface AvroConverterStrategy

All Superinterfaces:
DescribableComponent, Predicate<Class<?>>
All Known Implementing Classes:
SpecificRecordBaseConverterStrategy

public interface AvroConverterStrategy extends Predicate<Class<?>>, DescribableComponent
Strategy for Avro Converter. A strategy is selected upon the representation of the object in your runtime, assuming that the binary representation is always a binary byte array.
Since:
4.11.0
Author:
Simon Zambrovski, Jan Galinski
  • Method Details

    • test

      boolean test(Class<?> payloadType)
      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 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.
    • convertToSingleObjectEncoded

      @Nonnull byte[] convertToSingleObjectEncoded(@Nonnull Object object)
      Converts the given object to byte array using Avro single-object-encoding.
      Parameters:
      object - The object to convert.
      Returns:
      The byte array containing Avro Single Object Encoded bytes.
    • convertFromSingleObjectEncoded

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

      <T> T convertFromGenericRecord(@Nonnull org.apache.avro.generic.GenericRecord genericRecord, @Nonnull Class<T> type)
      Converts from Apache Avro generic record (intermediate representation).
      Type Parameters:
      T - The payload type to convert to.
      Parameters:
      genericRecord - The input object containing the generic record.
      type - The class of resulting object.
      Returns:
      deserialized object.
    • applyStrategyConfiguration

      default void applyStrategyConfiguration(@Nonnull AvroConverterStrategyConfiguration avroConverterStrategyConfiguration)
      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

      Parameters:
      avroConverterStrategyConfiguration - configuration passed after construction.