Skip to main content

DYNDB102: Missing JSON serializer package

FieldValue
CodeDYNDB102
SeverityError

Message

[JsonBlob] on property '{0}' requires referencing a JSON serializer package (SystemTextJson or NewtonsoftJson)

Description

JSON blob serialization requires a JSON serializer package reference. The [JsonBlob] attribute stores complex objects as a JSON string in DynamoDB, but needs either Oproto.FluentDynamoDb.SystemTextJson or Oproto.FluentDynamoDb.NewtonsoftJson to perform the serialization.

Example

The following code triggers this diagnostic:

// Project does NOT reference SystemTextJson or NewtonsoftJson package
[DynamoDbTable("Products")]
public partial class Product
{
[PartitionKey]
[DynamoDbAttribute("pk")]
public string Pk { get; set; } = string.Empty;

[JsonBlob]
[DynamoDbAttribute("metadata")]
public ProductMetadata Metadata { get; set; } = new();
}

Fix

The corrected version:

<!-- Add to your .csproj file -->
<PackageReference Include="Oproto.FluentDynamoDb.SystemTextJson" />
[DynamoDbTable("Products")]
public partial class Product
{
[PartitionKey]
[DynamoDbAttribute("pk")]
public string Pk { get; set; } = string.Empty;

[JsonBlob]
[DynamoDbAttribute("metadata")]
public ProductMetadata Metadata { get; set; } = new();
}