Class PowertoolsKafkaAvroSerializer
A Lambda serializer for Kafka events that handles Avro-formatted data. This serializer automatically deserializes the Avro binary format from base64-encoded strings in Kafka records and converts them to strongly-typed objects.
Implements
Inherited Members
Namespace: AWS.Lambda.Powertools.Kafka.Avro
Assembly: AWS.Lambda.Powertools.Kafka.Avro.dll
Syntax
public class PowertoolsKafkaAvroSerializer : PowertoolsKafkaSerializerBase, ILambdaSerializer
Examples
[assembly: LambdaSerializer(typeof(PowertoolsKafkaAvroSerializer))]
// Your Lambda handler will receive properly deserialized objects
public class Function
{
public void Handler(ConsumerRecords<string, Customer> records, ILambdaContext context)
{
foreach (var record in records)
{
Customer customer = record.Value;
context.Logger.LogInformation($"Processed customer {customer.Name}, age {customer.Age}");
}
}
}
Constructors
PowertoolsKafkaAvroSerializer()
Initializes a new instance of the PowertoolsKafkaAvroSerializer class with default JSON serialization options.
Declaration
public PowertoolsKafkaAvroSerializer()
PowertoolsKafkaAvroSerializer(JsonSerializerOptions)
Initializes a new instance of the PowertoolsKafkaAvroSerializer class with custom JSON serialization options.
Declaration
public PowertoolsKafkaAvroSerializer(JsonSerializerOptions jsonOptions)
Parameters
Type | Name | Description |
---|---|---|
JsonSerializerOptions | jsonOptions | Custom JSON serializer options to use during deserialization. |
PowertoolsKafkaAvroSerializer(JsonSerializerContext)
Initializes a new instance of the PowertoolsKafkaAvroSerializer class with a JSON serializer context for AOT-compatible serialization.
Declaration
public PowertoolsKafkaAvroSerializer(JsonSerializerContext serializerContext)
Parameters
Type | Name | Description |
---|---|---|
JsonSerializerContext | serializerContext | JSON serializer context for AOT compatibility. |
Methods
DeserializeComplexTypeFormat(byte[], Type, bool, SchemaMetadata?)
Deserializes complex (non-primitive) types using Avro format. Requires types to have a public static _SCHEMA field.
Declaration
protected override object? DeserializeComplexTypeFormat(byte[] data, Type targetType, bool isKey, SchemaMetadata? schemaMetadata = null)
Parameters
Type | Name | Description |
---|---|---|
byte[] | data | |
Type | targetType | |
bool | isKey | |
SchemaMetadata | schemaMetadata |
Returns
Type | Description |
---|---|
object |