Constructor AvroSharpSerializer
AvroSharpSerializer(ISchemaRegistryClient, AvroSharpSerializerConfig?, RuleRegistry?)
Creates a serializer of a generated type or a primitive, which AvroTypes knows. Generated types
register themselves on .NET 5 and later; on .NET Standard, pass the type's AvroTypeInfo to the other
constructor, or register it first.
public AvroSharpSerializer(ISchemaRegistryClient client, AvroSharpSerializerConfig? config = null, RuleRegistry? ruleRegistry = null)
Parameters
clientISchemaRegistryClientThe schema registry.
configAvroSharpSerializerConfigThe settings, or null for the defaults.
ruleRegistryRuleRegistryThe data contract rules, or null for Confluent.SchemaRegistry.RuleRegistry.GlobalInstance.
Exceptions
- InvalidOperationException
Tis not registered in AvroTypes (Confluent.Kafka'sNullneedn't be: its schema is"null"), or its schema holds null with Strict.- ArgumentException
confighas a key the serializer doesn't know, enables bothuse.latest.versionandauto.register.schemas(the default), or sets Strict for a value type.
AvroSharpSerializer(ISchemaRegistryClient, IEnumerable<Type>, AvroSharpSerializerConfig?, RuleRegistry?)
Creates a serializer of several record types, for a topic that carries them all: each value is written as its
own type, with its own record's schema, registered under its own subject with the TopicRecord or
Record subject name strategy. Confluent's serializer of ISpecificRecord writes the same.
public AvroSharpSerializer(ISchemaRegistryClient client, IEnumerable<Type> types, AvroSharpSerializerConfig? config = null, RuleRegistry? ruleRegistry = null)
Parameters
clientISchemaRegistryClientThe schema registry.
typesIEnumerable<Type>The record types: types AvroTypes knows, each a
T, of record schemas.configAvroSharpSerializerConfigThe settings, or null for the defaults.
ruleRegistryRuleRegistryThe data contract rules, or null for Confluent.SchemaRegistry.RuleRegistry.GlobalInstance.
Examples
new AvroSharpSerializer<object>(registry, [typeof(OrderPlaced), typeof(OrderShipped)], new() { SubjectNameStrategy = SubjectNameStrategy.TopicRecord })
Exceptions
- ArgumentException
No types are given, a type isn't a
Tor its schema isn't a record, two types have records of the same name or alias, orconfigis one the other constructors reject.- InvalidOperationException
A type is not one AvroTypes knows.
AvroSharpSerializer(ISchemaRegistryClient, AvroTypeInfo<T>, AvroSharpSerializerConfig?, RuleRegistry?)
Creates a serializer of the type that type reads and writes.
public AvroSharpSerializer(ISchemaRegistryClient client, AvroTypeInfo<T> type, AvroSharpSerializerConfig? config = null, RuleRegistry? ruleRegistry = null)
Parameters
clientISchemaRegistryClientThe schema registry.
typeAvroTypeInfo<T>The type's schema and serializers.
configAvroSharpSerializerConfigThe settings, or null for the defaults.
ruleRegistryRuleRegistryThe data contract rules, or null for Confluent.SchemaRegistry.RuleRegistry.GlobalInstance.
Exceptions
- ArgumentException
confighas a key the serializer doesn't know, enables bothuse.latest.versionandauto.register.schemas(the default), or sets Strict for a value type.- InvalidOperationException
The type's schema holds null, with Strict.