SystemTextJson
System.Text.Json serialization support for FluentDynamoDB. This is the recommended serialization package for new projects, especially those targeting AOT compilation.
Installation
dotnet add package Oproto.FluentDynamoDb.SystemTextJson
Key Features
- High Performance - Leverages System.Text.Json's optimized serialization
- Source Generation - Optional source-generated serializers for AOT
- Custom Converters - Built-in converters for DynamoDB-specific types
- Flexible Configuration - Full control over serialization options via
FluentDynamoDbOptions
Quick Start
Configure System.Text.Json at runtime using FluentDynamoDbOptions:
using Oproto.FluentDynamoDb;
using Oproto.FluentDynamoDb.SystemTextJson;
// Default options
var options = new FluentDynamoDbOptions()
.WithSystemTextJson();
var table = new DocumentTable(dynamoDbClient, "documents", options);
Custom JsonSerializerOptions
Pass custom JsonSerializerOptions to control serialization behavior:
var jsonOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = false,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
var options = new FluentDynamoDbOptions()
.WithSystemTextJson(jsonOptions);
var table = new DocumentTable(dynamoDbClient, "documents", options);
AOT-Compatible Configuration
For Native AOT scenarios, use a JsonSerializerContext to enable source-generated serialization:
// 1. Define your JSON context with types that need serialization
[JsonSerializable(typeof(DocumentContent))]
[JsonSerializable(typeof(List<string>))]
public partial class DocumentJsonContext : JsonSerializerContext
{
}
// 2. Configure FluentDynamoDbOptions with the context
var options = new FluentDynamoDbOptions()
.WithSystemTextJson(DocumentJsonContext.Default);
var table = new DocumentTable(dynamoDbClient, "documents", options);
Documentation
For complete documentation including entity definitions, usage examples, and custom converters, see the System.Text.Json Serialization Guide.