Class SpecificRecordBaseConverterStrategy
- All Implemented Interfaces:
Predicate<Class<?>>,DescribableComponent,AvroConverterStrategy
SpecificRecordBase as a superclass of all objects you are
working on.- Since:
- 4.11.0
- Author:
- Simon Zambrovski, Jan Galinski
-
Constructor Summary
ConstructorsConstructorDescriptionSpecificRecordBaseConverterStrategy(org.apache.avro.message.SchemaStore schemaStore, SchemaIncompatibilityChecker schemaIncompatibilityChecker) Constructs avro conversion strategy supporting conversion and deserialization of Java Avro classes extendingSpecificRecordBase. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyStrategyConfiguration(AvroConverterStrategyConfiguration avroConverterConfiguration) Sets the configuration for the strategy.<T> TconvertFromGenericRecord(org.apache.avro.generic.GenericRecord genericRecord, Class<T> readerType) Converts from Apache Avro generic record (intermediate representation).<T> TconvertFromSingleObjectEncoded(byte[] bytes, Class<T> readerType) Converts from single object encoded byte array.byte[]convertToSingleObjectEncoded(Object object) Converts the givenobjectto byte array using Avro single-object-encoding.voiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.booleanDetermines if this strategy supports givenpayloadType.
-
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 extendingSpecificRecordBase.- Parameters:
schemaStore- schema store to resolve schema from fingerprint.schemaIncompatibilityChecker- stateful utility to perform compatibility checks.
-
-
Method Details
-
convertToSingleObjectEncoded
Description copied from interface:AvroConverterStrategyConverts the givenobjectto byte array using Avro single-object-encoding.- Specified by:
convertToSingleObjectEncodedin interfaceAvroConverterStrategy- 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:AvroConverterStrategyConverts from single object encoded byte array.- Specified by:
convertFromSingleObjectEncodedin interfaceAvroConverterStrategy- 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:AvroConverterStrategyConverts from Apache Avro generic record (intermediate representation).- Specified by:
convertFromGenericRecordin interfaceAvroConverterStrategy- 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
Description copied from interface:AvroConverterStrategyDetermines if this strategy supports givenpayloadType. This means that we have either aSpecificRecordBasegenerated from a schema using apache-avro-maven-plugin or a kotlinx serializable class, written using avro4k.- Specified by:
testin interfaceAvroConverterStrategy- Specified by:
testin interfacePredicate<Class<?>>- Parameters:
payloadType- The payload type of object to de-/serialize, for exampleBankAccountCreated.class.- Returns:
trueif type is supported by this strategy,falseotherwise.
-
applyStrategyConfiguration
public void applyStrategyConfiguration(@Nonnull AvroConverterStrategyConfiguration avroConverterConfiguration) Description copied from interface:AvroConverterStrategySets 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:
applyStrategyConfigurationin interfaceAvroConverterStrategy- Parameters:
avroConverterConfiguration- configuration passed after construction.
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods 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
DescribableComponentimplementation 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 thedescribeTomethod, 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:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-