Interface AvroSerializerStrategy

All Superinterfaces:
Predicate<Class<?>>
All Known Implementing Classes:
SpecificRecordBaseSerializerStrategy

public interface AvroSerializerStrategy extends Predicate<Class<?>>
Serialization strategy for Avro Serializer.
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.
    • serializeToSingleObjectEncoded

      @Nonnull SerializedObject<byte[]> serializeToSingleObjectEncoded(@Nonnull Object object)
      Serializes object to byte array using Avro single-object-encoding.
      Parameters:
      object - object to serialize.
      Returns:
      byte array.
    • deserializeFromSingleObjectEncoded

      @Nonnull <T> T deserializeFromSingleObjectEncoded(@Nonnull SerializedObject<byte[]> serializedObject, @Nonnull Class<T> type)
      Deserializes from single object encoded byte array.
      Type Parameters:
      T - payload type to deserialize to.
      Parameters:
      serializedObject - serialized object containing single-object-encoded bytes.
      type - class of resulting object.
      Returns:
      deserialized object.
    • deserializeFromGenericRecord

      <T> T deserializeFromGenericRecord(SerializedObject<org.apache.avro.generic.GenericRecord> serializedObject, Class<T> type)
      Deserializes from Apache Avro generic record (intermediate representation).
      Type Parameters:
      T - payload type to deserialize to.
      Parameters:
      serializedObject - serialized object containing the generic record.
      type - class of resulting object.
      Returns:
      deserialized object.
    • applyConfig

      default void applyConfig(AvroSerializerStrategyConfig avroSerializerStrategyConfig)
      Sets the configuration for the strategy.

      This method is called by the AvroSerializer.Builder during instantiation of AvroSerializer, passing the builder 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 set by the AvroSerializer.Builder, passed via AvroSerializerStrategyConfig

      Parameters:
      avroSerializerStrategyConfig - configuration passed by the builder.