confluent-kafka-dotnet
Show / Hide Table of Contents

Class JsonDeserializerBuilder<T>

EXPERIMENTAL: subject to change or removal.

A builder of JsonDeserializer<T> instances, for use with SetValueDeserializerBuilder(IAsyncDeserializerBuilder<TValue>) and its key counterpart.

The consumer constructs the deserializer during its own construction, supplying its configuration and whether the deserializer is for the message key or value, and owns the result. There is no need to adapt the deserializer with AsSyncOverAsync() - the consumer does so itself.

Inheritance
object
SchemaRegistrySerdeBuilder<JsonDeserializerBuilder<T>>
JsonDeserializerBuilder<T>
Implements
IAsyncDeserializerBuilder<T>
Inherited Members
SchemaRegistrySerdeBuilder<JsonDeserializerBuilder<T>>.schemaRegistryClient
SchemaRegistrySerdeBuilder<JsonDeserializerBuilder<T>>.schemaRegistryConfig
SchemaRegistrySerdeBuilder<JsonDeserializerBuilder<T>>.schemaRegistryClientBuilder
SchemaRegistrySerdeBuilder<JsonDeserializerBuilder<T>>.ruleRegistry
SchemaRegistrySerdeBuilder<JsonDeserializerBuilder<T>>.SetSchemaRegistryClient(ISchemaRegistryClient)
SchemaRegistrySerdeBuilder<JsonDeserializerBuilder<T>>.SetSchemaRegistryConfig(SchemaRegistryConfig)
SchemaRegistrySerdeBuilder<JsonDeserializerBuilder<T>>.SetSchemaRegistryClientBuilder(ISchemaRegistryClientBuilder)
SchemaRegistrySerdeBuilder<JsonDeserializerBuilder<T>>.SetRuleRegistry(RuleRegistry)
SchemaRegistrySerdeBuilder<JsonDeserializerBuilder<T>>.ResolveSchemaRegistryClient(out bool)
SchemaRegistrySerdeBuilder<JsonDeserializerBuilder<T>>.ConstructSerde<TSerde>(Func<ISchemaRegistryClient, TSerde>, Action<TSerde>, Func<TSerde, Task>)
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Confluent.SchemaRegistry.Serdes
Assembly: Confluent.SchemaRegistry.Serdes.Json.dll
Syntax
public class JsonDeserializerBuilder<T> : SchemaRegistrySerdeBuilder<JsonDeserializerBuilder<T>>, IAsyncDeserializerBuilder<T> where T : class
Type Parameters
Name Description
T
Examples
using var consumer = new ConsumerBuilder<string, User>(consumerConfig)
    .SetValueDeserializerBuilder(new JsonDeserializerBuilder<User>()
        .SetSchemaRegistryConfig(schemaRegistryConfig))
    .Build();

Properties

RequiresSchemaRegistryClient

A JSON schema can be derived from the target type, so a Schema Registry client is optional unless an explicit schema is used.

Declaration
protected override bool RequiresSchemaRegistryClient { get; }
Property Value
Type Description
bool
Overrides
Confluent.SchemaRegistry.SchemaRegistrySerdeBuilder<Confluent.SchemaRegistry.Serdes.JsonDeserializerBuilder<T>>.RequiresSchemaRegistryClient

Methods

Build(IEnumerable<KeyValuePair<string, string>>, bool)

Build a deserializer.

Declaration
public IAsyncDeserializer<T> Build(IEnumerable<KeyValuePair<string, string>> config, bool isKey)
Parameters
Type Name Description
IEnumerable<KeyValuePair<string, string>> config

The configuration of the consumer the deserializer will be used by.

bool isKey

Whether the deserializer will be used to deserialize message keys (true) or message values (false).

Returns
Type Description
IAsyncDeserializer<T>

The deserializer.

SetDeserializerConfig(JsonDeserializerConfig)

The deserializer configuration (refer to JsonDeserializerConfig).

Declaration
public JsonDeserializerBuilder<T> SetDeserializerConfig(JsonDeserializerConfig deserializerConfig)
Parameters
Type Name Description
JsonDeserializerConfig deserializerConfig
Returns
Type Description
JsonDeserializerBuilder<T>

SetDeserializerInit(Func<JsonDeserializer<T>, Task>)

EXPERIMENTAL: subject to change or removal.

Setup to run on the deserializer once it has been built, for anything the other setters do not cover. It runs to completion within Build; if it throws, the deserializer's owned resources are released and the exception propagates.

Do not deserialize from it. It runs while the consumer is still being constructed, before the deserializer has been handed the resolver for the Kafka cluster id, so a subject name strategy that depends on that id - such as AssociatedNameStrategy - would resolve, and cache, the wrong subject. To warm the deserializer up, deserialize once the client has been constructed, or supply a deserializer constructed directly with KafkaClusterIdConfig configured instead of using the builder.

Declaration
public JsonDeserializerBuilder<T> SetDeserializerInit(Func<JsonDeserializer<T>, Task> deserializerInit)
Parameters
Type Name Description
Func<JsonDeserializer<T>, Task> deserializerInit
Returns
Type Description
JsonDeserializerBuilder<T>

SetJsonSchemaGeneratorSettings(NewtonsoftJsonSchemaGeneratorSettings)

The JSON schema generator settings to use when resolving the schema.

Declaration
public JsonDeserializerBuilder<T> SetJsonSchemaGeneratorSettings(NewtonsoftJsonSchemaGeneratorSettings jsonSchemaGeneratorSettings)
Parameters
Type Name Description
NewtonsoftJsonSchemaGeneratorSettings jsonSchemaGeneratorSettings
Returns
Type Description
JsonDeserializerBuilder<T>

SetSchema(Schema)

An explicit schema to validate against. Required when the schema has references.

Declaration
public JsonDeserializerBuilder<T> SetSchema(Schema schema)
Parameters
Type Name Description
Schema schema
Returns
Type Description
JsonDeserializerBuilder<T>

Implements

IAsyncDeserializerBuilder<T>
In this article