Class AbstractDeserializer<Schema, T>
- Namespace
- Solace.SchemaRegistry.Serdes.Core
- Assembly
- Solace.SchemaRegistry.Serdes.Core.dll
Abstract base class for deserializers that convert byte arrays into objects of type T. This class provides asynchronous deserialization capabilities for schema registry-based deserialization operations with proper resource management and schema resolution.
public abstract class AbstractDeserializer<Schema, T> : IAsyncDeserializer<T>, IDisposable
Type Parameters
SchemaThe schema type used for deserialization validation and processing
TThe type of object this deserializer produces
- Inheritance
-
AbstractDeserializer<Schema, T>
- Implements
-
IAsyncDeserializer<T>
- Derived
- Inherited Members
Remarks
This abstract class serves as the foundation for schema-aware deserializers that convert
byte arrays into objects of type T using schemas of type Schema.
It provides async-first deserialization with proper resource management and schema resolution.
Note: Schema registry connections will be established when configuring this deserializer. 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 deserialization.
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 deserializer with the specified properties.
public virtual void Configure(IDictionary<string, object> properties)
Parameters
propertiesIDictionary<string, object>A dictionary containing configuration properties for the deserializer
Remarks
This method establishes schema registry connections and initializes the deserializer. The specific configuration properties depend on the concrete implementation.
Exceptions
- ArgumentException
Thrown when configuration properties are invalid or missing required values
DeserializeAsync(string, ReadOnlyMemory<byte>, IDictionary<string, object>, CancellationToken)
Asynchronously deserializes the specified byte array into an object of type T using the configured schema resolver.
public Task<T> DeserializeAsync(string destinationName, ReadOnlyMemory<byte> payload, IDictionary<string, object> headers = null, CancellationToken token = default)
Parameters
destinationNamestringThe name of the destination topic or queue from which the data originated
payloadReadOnlyMemory<byte>The byte array payload to deserialize
headersIDictionary<string, object>Optional headers containing additional metadata that may influence deserialization
tokenCancellationTokenA cancellation token that can be used to cancel the operation
Returns
- Task<T>
A task that represents the asynchronous deserialization operation, containing the deserialized object of type T
Remarks
This method resolves the appropriate schema using artifact reference information from headers or payload, then delegates to the concrete implementation's DeserializePayload(ISchemaLookupResult<Schema>, ReadOnlyMemory<byte>, IMetadata, CancellationToken) method for actual deserialization.
Note: If schema identification cannot be resolved from headers or payload, deserialization may fail. Ensure that the appropriate schema identification information is available in headers or encoded in the payload.
Exceptions
- InvalidOperationException
Thrown when the deserializer has not been configured or the schema resolver is not available
- SerializationException
Thrown when deserialization fails due to schema validation, data conversion errors, or type mismatch
- OperationCanceledException
Thrown when the operation is canceled via the cancellation token
DeserializePayload(ISchemaLookupResult<Schema>, ReadOnlyMemory<byte>, IMetadata, CancellationToken)
When overridden in a derived class, deserializes the payload data using the resolved schema.
protected abstract ValueTask<T> DeserializePayload(ISchemaLookupResult<Schema> schemaLookup, ReadOnlyMemory<byte> payload, IMetadata metadata, CancellationToken token)
Parameters
schemaLookupISchemaLookupResult<Schema>The resolved schema lookup result containing the schema information
payloadReadOnlyMemory<byte>The byte array payload to deserialize
metadataIMetadataMetadata containing the destination name and headers for the deserialization context
tokenCancellationTokenA cancellation token that can be used to cancel the operation
Returns
- ValueTask<T>
A task representing the asynchronous deserialization operation, containing the deserialized object
Exceptions
- SerializationException
Thrown when deserialization fails due to schema validation or data conversion errors
- OperationCanceledException
Thrown when the operation is canceled via the cancellation token
Dispose()
Releases all resources used by the current instance of the AbstractDeserializer<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 deserialize will result in exceptions.
Dispose(bool)
Releases the unmanaged resources used by the AbstractDeserializer<Schema, T> and optionally releases the managed resources.
protected virtual void Dispose(bool disposing)
Parameters
disposingbooltrueto release both managed and unmanaged resources;falseto release only unmanaged resources.
SetSchemaParser(ISchemaParser<Schema>)
Sets the schema parser on the schema resolver.
protected void SetSchemaParser(ISchemaParser<Schema> schemaParser)
Parameters
schemaParserISchemaParser<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.