Oproto.FluentDynamoDb.SystemTextJson 0.8.0

dotnet add package Oproto.FluentDynamoDb.SystemTextJson --version 0.8.0
                    
NuGet\Install-Package Oproto.FluentDynamoDb.SystemTextJson -Version 0.8.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Oproto.FluentDynamoDb.SystemTextJson" Version="0.8.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Oproto.FluentDynamoDb.SystemTextJson" Version="0.8.0" />
                    
Directory.Packages.props
<PackageReference Include="Oproto.FluentDynamoDb.SystemTextJson" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Oproto.FluentDynamoDb.SystemTextJson --version 0.8.0
                    
#r "nuget: Oproto.FluentDynamoDb.SystemTextJson, 0.8.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Oproto.FluentDynamoDb.SystemTextJson@0.8.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Oproto.FluentDynamoDb.SystemTextJson&version=0.8.0
                    
Install as a Cake Addin
#tool nuget:?package=Oproto.FluentDynamoDb.SystemTextJson&version=0.8.0
                    
Install as a Cake Tool

Oproto.FluentDynamoDb.SystemTextJson

System.Text.Json serialization support for [JsonBlob] properties in Oproto.FluentDynamoDb entities. Fully compatible with Native AOT compilation and produces no trim warnings.

Installation

dotnet add package Oproto.FluentDynamoDb.SystemTextJson

Quick Start

Configure System.Text.Json serialization using the WithSystemTextJson() extension method on FluentDynamoDbOptions:

using Oproto.FluentDynamoDb;
using Oproto.FluentDynamoDb.SystemTextJson;

// Configure options with System.Text.Json (default settings)
var options = new FluentDynamoDbOptions()
    .WithSystemTextJson();

// Create your table with the configured options
var table = new OrderTable(dynamoDbClient, "Orders", options);

Configuration Options

Default Options

Use WithSystemTextJson() with no parameters for default System.Text.Json behavior:

var options = new FluentDynamoDbOptions()
    .WithSystemTextJson();

Custom JsonSerializerOptions

Use WithSystemTextJson(JsonSerializerOptions) to customize serialization behavior:

using System.Text.Json;
using System.Text.Json.Serialization;

var jsonOptions = new JsonSerializerOptions
{
    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
    DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
    WriteIndented = false
};

var options = new FluentDynamoDbOptions()
    .WithSystemTextJson(jsonOptions);

AOT-Compatible with JsonSerializerContext

For Native AOT and trimmed applications, use WithSystemTextJson(JsonSerializerContext) with a source-generated context:

using System.Text.Json.Serialization;

// 1. Define a JsonSerializerContext for your types
[JsonSerializable(typeof(OrderMetadata))]
[JsonSerializable(typeof(CustomerPreferences))]
internal partial class MyJsonContext : JsonSerializerContext { }

// 2. Configure FluentDynamoDbOptions with the context
var options = new FluentDynamoDbOptions()
    .WithSystemTextJson(MyJsonContext.Default);

var table = new OrderTable(dynamoDbClient, "Orders", options);

Complete Usage Example

using Amazon.DynamoDBv2;
using Oproto.FluentDynamoDb;
using Oproto.FluentDynamoDb.SystemTextJson;
using Oproto.FluentDynamoDb.Attributes;
using System.Text.Json;
using System.Text.Json.Serialization;

// Define your entity with a [JsonBlob] property
[DynamoDbTable("orders")]
public partial class Order
{
    [PartitionKey]
    [DynamoDbAttribute("pk")]
    public string OrderId { get; set; } = string.Empty;
    
    [SortKey]
    [DynamoDbAttribute("sk")]
    public string Sk { get; set; } = "ORDER";
    
    [JsonBlob]
    [DynamoDbAttribute("metadata")]
    public OrderMetadata Metadata { get; set; } = new();
}

public class OrderMetadata
{
    public string Source { get; set; } = string.Empty;
    public Dictionary<string, string> Tags { get; set; } = new();
    public DateTime CreatedAt { get; set; }
}

// For AOT: Define a JsonSerializerContext
[JsonSerializable(typeof(OrderMetadata))]
internal partial class OrderJsonContext : JsonSerializerContext { }

// Usage
public class OrderService
{
    private readonly OrderTable _table;
    
    public OrderService(IAmazonDynamoDB client)
    {
        // Option 1: Default settings (reflection-based)
        var options = new FluentDynamoDbOptions()
            .WithSystemTextJson();
        
        // Option 2: Custom settings
        var customOptions = new FluentDynamoDbOptions()
            .WithSystemTextJson(new JsonSerializerOptions
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            });
        
        // Option 3: AOT-compatible (recommended for Lambda)
        var aotOptions = new FluentDynamoDbOptions()
            .WithSystemTextJson(OrderJsonContext.Default);
        
        _table = new OrderTable(client, "orders", aotOptions);
    }
    
    public async Task<Order?> GetOrderAsync(string orderId)
    {
        return await _table.Orders.Get(orderId).GetItemAsync();
    }
    
    public async Task SaveOrderAsync(Order order)
    {
        await _table.Orders.Put(order).PutAsync();
    }
}

Features

Feature Description
Full AOT Compatibility No reflection when using JsonSerializerContext
Trim Safe No trim warnings with source-generated context
Customizable Full control via JsonSerializerOptions
High Performance Optimized for speed and low allocations

Comparison with NewtonsoftJson

Feature SystemTextJson NewtonsoftJson
AOT Compatible ✅ Full support ⚠️ Limited
Trim Safe ✅ No warnings ❌ Warnings
Reflection ❌ None (with context) ✅ Required
Performance ⚡ Faster 🐢 Slower

Choose this package when:

  • Building AWS Lambda functions with Native AOT
  • Deploying to environments with trimming enabled
  • Optimizing for performance and binary size

Choose NewtonsoftJson when:

  • You need advanced features like TypeNameHandling
  • Working with legacy code that depends on Newtonsoft.Json
  • You need more flexible polymorphic serialization

Error Handling

If you use [JsonBlob] properties without configuring a JSON serializer, you'll get a clear runtime exception:

InvalidOperationException: Property 'Metadata' has [JsonBlob] attribute but no JSON serializer is configured. 
Call .WithSystemTextJson() or .WithNewtonsoftJson() on FluentDynamoDbOptions.

License

MIT License - see LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.8.0 163 12/5/2025