Class JsonSerializerBuilder<T>
EXPERIMENTAL: subject to change or removal.
A builder of JsonSerializer<T> instances, for use with SetValueSerializerBuilder(IAsyncSerializerBuilder<TValue>) and its key counterpart.
The producer constructs the serializer during its own construction, supplying its configuration and whether the serializer is for the message key or value, and owns the result.
Implements
Inherited Members
Namespace: Confluent.SchemaRegistry.Serdes
Assembly: Confluent.SchemaRegistry.Serdes.Json.dll
Syntax
public class JsonSerializerBuilder<T> : SchemaRegistrySerdeBuilder<JsonSerializerBuilder<T>>, IAsyncSerializerBuilder<T> where T : class
Type Parameters
| Name | Description |
|---|---|
| T |
Examples
using var producer = new ProducerBuilder<string, User>(producerConfig)
.SetValueSerializerBuilder(new JsonSerializerBuilder<User>()
.SetSchemaRegistryConfig(schemaRegistryConfig))
.Build();
Methods
Build(IEnumerable<KeyValuePair<string, string>>, bool)
Build a serializer.
Declaration
public IAsyncSerializer<T> Build(IEnumerable<KeyValuePair<string, string>> config, bool isKey)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<KeyValuePair<string, string>> | config | The configuration of the producer the serializer will be used by. |
| bool | isKey | Whether the serializer will be used to serialize message keys (true) or message values (false). |
Returns
| Type | Description |
|---|---|
| IAsyncSerializer<T> | The serializer. |
SetJsonSchemaGeneratorSettings(NewtonsoftJsonSchemaGeneratorSettings)
The JSON schema generator settings to use when deriving the schema
from T.
Declaration
public JsonSerializerBuilder<T> SetJsonSchemaGeneratorSettings(NewtonsoftJsonSchemaGeneratorSettings jsonSchemaGeneratorSettings)
Parameters
| Type | Name | Description |
|---|---|---|
| NewtonsoftJsonSchemaGeneratorSettings | jsonSchemaGeneratorSettings |
Returns
| Type | Description |
|---|---|
| JsonSerializerBuilder<T> |
SetSchema(Schema)
An explicit schema to use, rather than deriving one from
T. Required when the schema has references.
Declaration
public JsonSerializerBuilder<T> SetSchema(Schema schema)
Parameters
| Type | Name | Description |
|---|---|---|
| Schema | schema |
Returns
| Type | Description |
|---|---|
| JsonSerializerBuilder<T> |
SetSerializerConfig(JsonSerializerConfig)
The serializer configuration (refer to JsonSerializerConfig).
Declaration
public JsonSerializerBuilder<T> SetSerializerConfig(JsonSerializerConfig serializerConfig)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonSerializerConfig | serializerConfig |
Returns
| Type | Description |
|---|---|
| JsonSerializerBuilder<T> |
SetSerializerInit(Func<JsonSerializer<T>, Task>)
EXPERIMENTAL: subject to change or removal.
Setup to run on the serializer once it has been built, for anything
the other setters do not cover. It runs to completion within
Build; if it throws, the serializer's owned resources are
released and the exception propagates.
Do not serialize from it. It runs while the producer is still being constructed, before the serializer 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 serializer up, serialize once the client has been constructed, or supply a serializer constructed directly with KafkaClusterIdConfig configured instead of using the builder.
Declaration
public JsonSerializerBuilder<T> SetSerializerInit(Func<JsonSerializer<T>, Task> serializerInit)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<JsonSerializer<T>, Task> | serializerInit |
Returns
| Type | Description |
|---|---|
| JsonSerializerBuilder<T> |