confluent-kafka-dotnet
Show / Hide Table of Contents

Class JsonSerializer<T>

JSON Serializer.

Inheritance
object
AsyncSerde<JsonSchema>
AsyncSerializer<T, JsonSchema>
JsonSerializer<T>
Implements
IAsyncSerializer<T>
Inherited Members
AsyncSerializer<T, JsonSchema>.autoRegisterSchema
AsyncSerializer<T, JsonSchema>.normalizeSchemas
AsyncSerializer<T, JsonSchema>.schemaIdEncoder
AsyncSerializer<T, JsonSchema>.initialBufferSize
AsyncSerializer<T, JsonSchema>.subjectsRegistered
AsyncSerializer<T, JsonSchema>.SerializeAsync(T, SerializationContext)
AsyncSerde<JsonSchema>.schemaRegistryClient
AsyncSerde<JsonSchema>.ruleRegistry
AsyncSerde<JsonSchema>.useSchemaId
AsyncSerde<JsonSchema>.useLatestVersion
AsyncSerde<JsonSchema>.latestCompatibilityStrict
AsyncSerde<JsonSchema>.useLatestWithMetadata
AsyncSerde<JsonSchema>.subjectNameStrategy
AsyncSerde<JsonSchema>.serdeMutex
AsyncSerde<JsonSchema>.GetSubjectName(string, bool, string)
AsyncSerde<JsonSchema>.GetWriterSchema(string, SchemaId, string)
AsyncSerde<JsonSchema>.GetParsedSchema(Schema)
AsyncSerde<JsonSchema>.ResolveReferences(Schema)
AsyncSerde<JsonSchema>.IgnoreReference(string)
AsyncSerde<JsonSchema>.GetMigrations(string, Schema, RegisteredSchema)
AsyncSerde<JsonSchema>.GetReaderSchema(string, Schema)
AsyncSerde<JsonSchema>.ExecuteMigrations(IList<Migration>, bool, string, string, Headers, object)
AsyncSerde<JsonSchema>.ExecuteRules(bool, string, string, Headers, RuleMode, Schema, Schema, object, FieldTransformer)
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 JsonSerializer<T> : AsyncSerializer<T, JsonSchema>, IAsyncSerializer<T> where T : class
Type Parameters
Name Description
T
Remarks

Serialization format: byte 0: A magic byte that identifies this as a message with Confluent Platform framing. bytes 1-4: Unique global id of the JSON schema associated with the data (as registered in Confluent Schema Registry), big endian. following bytes: The JSON data (utf8)

Internally, the serializer uses Newtonsoft.Json for serialization and NJsonSchema for schema creation and validation. You can use any property annotations recognised by these libraries.

Note: Off-the-shelf libraries do not yet exist to enable integration of System.Text.Json and JSON Schema, so this is not yet supported by the serializer.

Constructors

JsonSerializer(ISchemaRegistryClient, Schema, JsonSerializerConfig, JsonSchemaGeneratorSettings, RuleRegistry)

Initialize a new instance of the JsonSerializer class with a given Schema.

Declaration
public JsonSerializer(ISchemaRegistryClient schemaRegistryClient, Schema schema, JsonSerializerConfig config = null, JsonSchemaGeneratorSettings jsonSchemaGeneratorSettings = null, RuleRegistry ruleRegistry = null)
Parameters
Type Name Description
ISchemaRegistryClient schemaRegistryClient

Confluent Schema Registry client instance.

Schema schema

Schema to use for validation, used when external schema references are present in the schema. Populate the References list of the schema for the same.

JsonSerializerConfig config

Serializer configuration.

JsonSchemaGeneratorSettings jsonSchemaGeneratorSettings

JSON schema generator settings.

RuleRegistry ruleRegistry

JsonSerializer(ISchemaRegistryClient, JsonSerializerConfig, JsonSchemaGeneratorSettings, RuleRegistry)

Initialize a new instance of the JsonSerializer class.

Declaration
public JsonSerializer(ISchemaRegistryClient schemaRegistryClient, JsonSerializerConfig config = null, JsonSchemaGeneratorSettings jsonSchemaGeneratorSettings = null, RuleRegistry ruleRegistry = null)
Parameters
Type Name Description
ISchemaRegistryClient schemaRegistryClient

Confluent Schema Registry client instance.

JsonSerializerConfig config

Serializer configuration.

JsonSchemaGeneratorSettings jsonSchemaGeneratorSettings

JSON schema generator settings.

RuleRegistry ruleRegistry

Methods

ParseSchema(Schema)

Declaration
protected override Task<JsonSchema> ParseSchema(Schema schema)
Parameters
Type Name Description
Schema schema
Returns
Type Description
Task<JsonSchema>
Overrides
AsyncSerde<JsonSchema>.ParseSchema(Schema)

SerializeAsync(T, SerializationContext)

Serialize an instance of type T to a UTF8 encoded JSON representation. The serialized data is preceeded by:

  1. A "magic byte" (1 byte) that identifies this as a message with Confluent Platform framing.
  2. The id of the schema as registered in Confluent's Schema Registry (4 bytes, network byte order). This call may block or throw on first use for a particular topic during schema registration / verification.
Declaration
public override Task<byte[]> SerializeAsync(T value, SerializationContext context)
Parameters
Type Name Description
T value

The value to serialize.

SerializationContext context

Context relevant to the serialize operation.

Returns
Type Description
Task<byte[]>

A Task that completes with value serialized as a byte array.

Overrides
AsyncSerializer<T, JsonSchema>.SerializeAsync(T, SerializationContext)

Implements

IAsyncSerializer<T>
In this article