Table of Contents

Class AbstractSerializer<Schema, T>

Namespace
Solace.SchemaRegistry.Serdes.Core
Assembly
Solace.SchemaRegistry.Serdes.Core.dll

A serializer base class that processes configuration objects and provides asynchronous serialization capabilities for schema registry-based serialization operations.

public abstract class AbstractSerializer<Schema, T> : IAsyncSerializer<T>, IDisposable

Type Parameters

Schema

The schema type used for serialization validation and processing

T

The type of object to be serialized

Inheritance
AbstractSerializer<Schema, T>
Implements
IAsyncSerializer<T>
Derived
Inherited Members

Remarks

This abstract class serves as the foundation for schema-aware serializers that convert objects of type T into byte arrays using schemas of type Schema. It provides async-first serialization with proper resource management and schema resolution.

Note: Schema registry connections will be established when configuring this serializer. Always call Dispose() when finished to properly clean up resources and prevent resource leaks.

Properties

SchemaResolver

Gets the schema resolver instance used for resolving schemas during serialization.

public ISchemaResolver<Schema, T> SchemaResolver { get; protected set; }

Property Value

ISchemaResolver<Schema, T>

The ISchemaResolver<S, T> instance, or null if not yet configured.

Methods

Configure(IDictionary<string, object>)

Configures this serializer with the specified properties.

public virtual void Configure(IDictionary<string, object> properties)

Parameters

properties IDictionary<string, object>

A dictionary containing configuration properties for the serializer

Remarks

This method establishes schema registry connections and initializes the serializer. The specific configuration properties depend on the concrete implementation.

Exceptions

ArgumentException

Thrown when configuration properties are invalid or missing required values

InvalidOperationException

Thrown when the serializer cannot be properly configured

Dispose()

Releases all resources used by the current instance of the AbstractSerializer<Schema, T> class.

public void Dispose()

Remarks

This method disposes of the schema resolver and any other managed resources. It can be called multiple times safely without adverse effects. Once disposed, attempts to serialize will result in exceptions.

Dispose(bool)

Releases the unmanaged resources used by the AbstractSerializer<Schema, T> and optionally releases the managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

HandleHeaders(IRecord<T>, ISchemaLookupResult<Schema>)

Updates the headers with schema metadata after serialization.

protected virtual void HandleHeaders(IRecord<T> record, ISchemaLookupResult<Schema> lookup)

Parameters

record IRecord<T>

A Record of header properties that can be modified

lookup ISchemaLookupResult<Schema>

The schema lookup result containing the artifact reference with the schema ID

SerializeAsync(string, T, IDictionary<string, object>, CancellationToken)

Asynchronously serializes the specified object using the configured schema resolver.

public Task<byte[]> SerializeAsync(string destinationName, T obj, IDictionary<string, object> headers = null, CancellationToken token = default)

Parameters

destinationName string

The name of the destination topic or queue where the object will be sent

obj T

The object to serialize

headers IDictionary<string, object>

Optional headers containing additional metadata that may influence serialization

token CancellationToken

A cancellation token that can be used to cancel the operation

Returns

Task<byte[]>

A task that represents the asynchronous serialization operation, containing the serialized byte array

Exceptions

InvalidOperationException

Thrown when the serializer has not been configured or the schema resolver is not available

SerializationException

Thrown when serialization fails due to schema validation or data conversion errors

ArgumentNullException

Thrown when destinationName is null

OperationCanceledException

Thrown when the operation is canceled via the cancellation token

SerializePayload(IRecord<T>, ISchemaLookupResult<Schema>, Stream, CancellationToken)

When overridden in a derived class, serializes the payload data using the resolved schema.

protected abstract ValueTask SerializePayload(IRecord<T> record, ISchemaLookupResult<Schema> schemaLookup, Stream outputStream, CancellationToken token)

Parameters

record IRecord<T>

The record containing the data and metadata for serialization

schemaLookup ISchemaLookupResult<Schema>

The resolved schema lookup result containing the schema information

outputStream Stream

The output stream to write the serialized data to

token CancellationToken

A cancellation token that can be used to cancel the operation

Returns

ValueTask

A task representing the asynchronous serialization operation

Exceptions

SerializationException

Thrown when serialization fails due to schema validation or data conversion errors

OperationCanceledException

Thrown when the operation is canceled via the cancellation token

SetSchemaParser(ISchemaParser<Schema>)

Sets the schema parser on the schema resolver.

protected void SetSchemaParser(ISchemaParser<Schema> schemaParser)

Parameters

schemaParser ISchemaParser<Schema>

The schema parser to use for parsing schemas

Remarks

This method should be called by derived classes after calling base.Configure() to set the appropriate schema parser for the specific schema type.

See Also

IAsyncSerializer<T>