Table of Contents

Constructor AvroSharpSerializer

Namespace
AvroSharp.Confluent
Assembly
AvroSharp.Confluent.dll

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

client ISchemaRegistryClient

The schema registry.

config AvroSharpSerializerConfig

The settings, or null for the defaults.

ruleRegistry RuleRegistry

The data contract rules, or null for Confluent.SchemaRegistry.RuleRegistry.GlobalInstance.

Exceptions

InvalidOperationException

T is not registered in AvroTypes (Confluent.Kafka's Null needn't be: its schema is "null"), or its schema holds null with Strict.

ArgumentException

config has a key the serializer doesn't know, enables both use.latest.version and auto.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

client ISchemaRegistryClient

The schema registry.

types IEnumerable<Type>

The record types: types AvroTypes knows, each a T, of record schemas.

config AvroSharpSerializerConfig

The settings, or null for the defaults.

ruleRegistry RuleRegistry

The 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 T or its schema isn't a record, two types have records of the same name or alias, or config is 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

client ISchemaRegistryClient

The schema registry.

type AvroTypeInfo<T>

The type's schema and serializers.

config AvroSharpSerializerConfig

The settings, or null for the defaults.

ruleRegistry RuleRegistry

The data contract rules, or null for Confluent.SchemaRegistry.RuleRegistry.GlobalInstance.

Exceptions

ArgumentException

config has a key the serializer doesn't know, enables both use.latest.version and auto.register.schemas (the default), or sets Strict for a value type.

InvalidOperationException

The type's schema holds null, with Strict.