Class JsonSerializer<T>
JSON Serializer.
Implements
Inherited Members
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
SerializeAsync(T, SerializationContext)
Serialize an instance of type T
to a UTF8 encoded JSON
representation. The serialized data is preceeded by:
- A "magic byte" (1 byte) that identifies this as a message with Confluent Platform framing.
- 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
|