Class AvroSerializer<T>
- Namespace
- Solace.SchemaRegistry.Serdes.Avro
- Assembly
- Solace.SchemaRegistry.Serdes.Avro.dll
An AVRO serializer that converts objects of type T into byte arrays with AVRO schema validation. Configuration properties can be found in AvroProperties.
public class AvroSerializer<T> : AbstractSerializer<Schema, T>, IAsyncSerializer<T>, IDisposable
Type Parameters
TThe type of object to be serialized. Should be an AVRO primitive, or castable to either a GenericRecord or SpecificRecord.
- Inheritance
-
AbstractSerializer<Schema, T>AvroSerializer<T>
- Implements
-
IAsyncSerializer<T>
- Inherited Members
Remarks
AvroSerializer<T> requires schema resolution through headers for proper operation. Schema ID must be available during serialization to resolve and apply the appropriate schema.
Values may be an Avro.Specific.ISpecificRecord, a Avro.Generic.GenericRecord, or an AVRO primitive.
Serializing null requires T to be object.
Note: This serializer establishes connections that may prevent application exit. Always call Dispose() when finished to properly clean up resources.
Methods
Configure(IDictionary<string, object>)
Configures this serializer with the specified properties and injects the AVRO schema parser.
public override void Configure(IDictionary<string, object> properties)
Parameters
propertiesIDictionary<string, object>A dictionary containing configuration properties for the serializer
Exceptions
- ArgumentException
Thrown when required configuration properties are missing or invalid
HandleHeaders(IRecord<T>, ISchemaLookupResult<Schema>)
Updates the headers with schema metadata and the AVRO encoding type after serialization.
protected override void HandleHeaders(IRecord<T> record, ISchemaLookupResult<Schema> lookup)
Parameters
recordIRecord<T>The record whose headers will be updated
lookupISchemaLookupResult<Schema>The schema lookup result containing the artifact reference with the schema ID
SerializePayload(IRecord<T>, ISchemaLookupResult<Schema>, Stream, CancellationToken)
Serializes the payload data using the resolved AVRO schema and the configured encoding.
protected override ValueTask SerializePayload(IRecord<T> record, ISchemaLookupResult<Schema> schemaLookup, Stream outputStream, CancellationToken token)
Parameters
recordIRecord<T>The record containing the data to serialize
schemaLookupISchemaLookupResult<Schema>The resolved schema lookup result containing the AVRO schema
outputStreamStreamThe output stream to write the serialized data to
tokenCancellationTokenCancellation token for the operation
Returns
- ValueTask
A task representing the asynchronous serialization operation
Exceptions
- SerializationException
Thrown when AVRO serialization fails
- OperationCanceledException
Thrown when the operation is canceled via the cancellation token