Skip to content

Feature request: Add strongly-typed batch processing with automatic deserialization support #969

@hjgraca

Description

@hjgraca

Use case

Currently, batch processing utility requires developers to manually deserialize event record data within their record handlers. This leads to repetitive boilerplate code and potential inconsistencies across different handlers. Developers need to:

  • Extract raw data from different event types (SQS body, Kinesis data, DynamoDB records)
  • Manually deserialize JSON strings to strongly-typed objects
public class OrderHandler : ISqsRecordHandler
{
    public async Task<RecordHandlerResult> HandleAsync(SQSEvent.SQSMessage record, CancellationToken cancellationToken)
    {
        // Manual deserialization in every handler
        var order = JsonSerializer.Deserialize<Order>(record.Body);

        await ProcessOrder(order);
        return RecordHandlerResult.Successful;
    }
}

Solution/User Experience

Introduce strongly-typed batch processing that automatically handles deserialization:

New Interface-based Approach:

public class OrderHandler : ITypedRecordHandler<Order>
{
    public async Task<RecordHandlerResult> HandleAsync(Order order, CancellationToken cancellationToken)
    {
        // Direct access to strongly-typed object - no manual deserialization!
        await ProcessOrder(order);
        return RecordHandlerResult.Successful;
    }
}

Key Features

  • Automatic deserialization to strongly-typed objects
  • Support for SQS, Kinesis, and DynamoDB events
  • AOT compatibility with JsonSerializerContext
  • Configurable error handling for deserialization failures
  • Full backward compatibility

Alternative solutions

Acknowledgment

Metadata

Metadata

Assignees

Labels

area/batchBatch utilityfeature-requestNew or enhancements to existing features

Projects

Status

👀 In review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions