Skip to content

Amazon.Lambda.KafkaEvents.KafkaEvent cannot be deserialized #1070

@gabriel-myob

Description

@gabriel-myob

Description

The latest version of Amazon.Lambda.KafkaEvents.KafkaEvent cannot deserialize events when using SelfManagedKafka as source events.

Reproduction Steps

The hander function signature looks like

[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
...
...
    public async Task FunctionHandler(KafkaEvent kafkaEvent, ILambdaContext context){...}

Logs

Error converting the Lambda event JSON payload to type Amazon.Lambda.KafkaEvents.KafkaEvent: The JSON value could not be converted to System.String. Path: $.records.TOPIC[0].partition | LineNumber: 0 | BytePositionInLine: 377.: JsonSerializerException
at Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer.Deserialize[T](Stream requestStream)
at lambda_method(Closure , Stream , Stream , LambdaContextInternal )

at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& readStack, Utf8JsonReader& reader, Exception ex)
at System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack)
at System.Text.Json.JsonSerializer.ReadCore(Type returnType, JsonSerializerOptions options, Utf8JsonReader& reader)
at System.Text.Json.JsonSerializer.ParseCore(ReadOnlySpan1 utf8Json, Type returnType, JsonSerializerOptions options) at System.Text.Json.JsonSerializer.Deserialize[TValue](ReadOnlySpan1 utf8Json, JsonSerializerOptions options)
at Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer.Deserialize[T](Stream requestStream)
Cannot get the value of a token type 'Number' as a string.: InvalidOperationException
at System.Text.Json.Utf8JsonReader.GetString()
at System.Text.Json.Serialization.Converters.JsonConverterString.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
at System.Text.Json.JsonPropertyInfoNotNullable`4.OnRead(ReadStack& state, Utf8JsonReader& reader)
at System.Text.Json.JsonPropertyInfo.Read(JsonTokenType tokenType, ReadStack& state, Utf8JsonReader& reader)
at System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack)

Environment

Resolution

I noticed that there has been a change to the type Partition property - used to be int now is string. Any reason for that?
https://github.com/aws/aws-lambda-dotnet/blame/b49dfae373538aad2811340cd2a03b478cb59318/Libraries/src/Amazon.Lambda.KafkaEvents/KafkaEvent.cs#L46


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions