AvroSerializer class

Avro serializer that obtains schemas from a schema registry and does not pack schemas into its payloads.

Constructors

AvroSerializer<MessageT>(SchemaRegistry, AvroSerializerOptions<MessageT>)

Creates a new serializer.

Methods

deserialize(MessageT, DeserializeOptions)

Deserializes the payload of the message using the schema ID in the content type field if no schema was provided.

serialize(unknown, string)

serializes the value parameter according to the input schema and creates a message with the serialized data.

Constructor Details

AvroSerializer<MessageT>(SchemaRegistry, AvroSerializerOptions<MessageT>)

Creates a new serializer.

new AvroSerializer(client: SchemaRegistry, options?: AvroSerializerOptions<MessageT>)

Parameters

client
SchemaRegistry

Schema Registry where schemas are registered and obtained. Usually this is a SchemaRegistryClient instance.

options

AvroSerializerOptions<MessageT>

Method Details

deserialize(MessageT, DeserializeOptions)

Deserializes the payload of the message using the schema ID in the content type field if no schema was provided.

function deserialize(message: MessageT, options?: DeserializeOptions): Promise<unknown>

Parameters

message

MessageT

The message with the payload to be deserialized.

options
DeserializeOptions

Decoding options.

Returns

Promise<unknown>

The deserialized value.

serialize(unknown, string)

serializes the value parameter according to the input schema and creates a message with the serialized data.

function serialize(value: unknown, schema: string): Promise<MessageT>

Parameters

value

unknown

The value to serialize.

schema

string

The Avro schema to use.

Returns

Promise<MessageT>

A new message with the serialized value. The structure of message is constrolled by the message factory option.