NEventStore.Serialization.Json 10.2.0

dotnet add package NEventStore.Serialization.Json --version 10.2.0
                    
NuGet\Install-Package NEventStore.Serialization.Json -Version 10.2.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="NEventStore.Serialization.Json" Version="10.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NEventStore.Serialization.Json" Version="10.2.0" />
                    
Directory.Packages.props
<PackageReference Include="NEventStore.Serialization.Json" />
                    
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 NEventStore.Serialization.Json --version 10.2.0
                    
#r "nuget: NEventStore.Serialization.Json, 10.2.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 NEventStore.Serialization.Json@10.2.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=NEventStore.Serialization.Json&version=10.2.0
                    
Install as a Cake Addin
#tool nuget:?package=NEventStore.Serialization.Json&version=10.2.0
                    
Install as a Cake Tool

NEventStore.Serialization.Json

NEventStore.Serialization.Json is the Newtonsoft.Json serializer for NEventStore. It is the compatibility contract that the System.Text.Json serializer follows so either package can be used for the same persisted JSON.

Wireup

var store = Wireup.Init()
    .UsingInMemoryPersistence()
    .UsingJsonSerialization()
    .Build();

Custom Newtonsoft settings can be supplied, and root known types can be overridden:

var serializer = new JsonSerializer(
    new JsonSerializerSettings(),
    typeof(List<EventMessage>),
    typeof(Dictionary<string, object>));

The default known types are:

  • List<EventMessage>
  • Dictionary<string, object>

Passing null or an empty known-type array keeps those defaults. Passing a non-empty array replaces them.

Implementation Model

The serializer has two internal Newtonsoft serializers:

  • Untyped serializer for known root types: TypeNameHandling.Auto, DefaultValueHandling.Ignore, NullValueHandling.Ignore.
  • Typed serializer for every other root type: TypeNameHandling.All, DefaultValueHandling.Ignore, NullValueHandling.Ignore.

Known root types are intentionally written without a root $type wrapper. Their polymorphic object members still receive $type metadata when the runtime value is not assignable from the declared type. This is what preserves event body, header, and snapshot payload types.

Unknown root types are written with root $type metadata. This keeps snapshots and custom serialized root objects self-describing.

Compatibility Contract

The JSON contract is based on Newtonsoft.Json metadata names:

  • $type stores an assembly-qualified CLR type name.
  • $values stores array contents when the typed value itself is an array or collection.
  • Null properties and default values are omitted.
  • Known root types are read and written without root $type metadata.
  • Polymorphic object values are read and written with $type metadata when needed.

The System.Text.Json serializer emits and reads the same metadata contract for the NEventStore cases that require polymorphism. The two serializers are wire-compatible; they are not required to produce byte-for-byte identical JSON when static property types already provide enough type information.

Serialized Data Examples

Assembly versions are shortened in these examples. Real payloads contain full assembly-qualified names.

Event Messages

Source object:

var messages = new List<EventMessage>
{
    new EventMessage { Body = "some value" },
    new EventMessage { Body = 42 },
    new EventMessage { Body = new SimpleMessage { Count = 1234, Value = "Hello" } }
};

JSON shape:

[
  {
    "Headers": {},
    "Body": "some value"
  },
  {
    "Headers": {},
    "Body": 42
  },
  {
    "Headers": {},
    "Body": {
      "$type": "NEventStore.Persistence.AcceptanceTests.SimpleMessage, NEventStore.Persistence.AcceptanceTests",
      "Id": "00000000-0000-0000-0000-000000000000",
      "Created": "0001-01-01T00:00:00",
      "Value": "Hello",
      "Count": 1234,
      "Contents": []
    }
  }
]

List<EventMessage> is a known root type, so the array has no root $type. The third Body is declared as object, so it has $type metadata.

Commit Headers

Source object:

var headers = new Dictionary<string, object>
{
    ["HeaderKey"] = "SomeValue",
    ["NumericKey"] = 42,
    ["ComplexKey"] = new SimpleMessage { Count = 1234 }
};

JSON shape:

{
  "HeaderKey": "SomeValue",
  "NumericKey": 42,
  "ComplexKey": {
    "$type": "NEventStore.Persistence.AcceptanceTests.SimpleMessage, NEventStore.Persistence.AcceptanceTests",
    "Id": "00000000-0000-0000-0000-000000000000",
    "Created": "0001-01-01T00:00:00",
    "Count": 1234,
    "Contents": []
  }
}

Dictionary<string, object> is a known root type, so the dictionary itself has no root $type. Complex values are typed.

Snapshot Payloads

Source object:

var snapshot = new Snapshot("stream-1", 42, new Dictionary<string, List<int>>
{
    ["values"] = [1, 2, 3]
});

JSON shape:

{
  "$type": "NEventStore.Snapshot, NEventStore",
  "BucketId": "default",
  "StreamId": "stream-1",
  "StreamRevision": 42,
  "Payload": {
    "$type": "System.Collections.Generic.Dictionary`2[[System.String,...],[System.Collections.Generic.List`1[[System.Int32,...]],...]], ...",
    "values": {
      "$type": "System.Collections.Generic.List`1[[System.Int32,...]], ...",
      "$values": [1, 2, 3]
    }
  }
}

Snapshot is not a known root type, so the root has $type. Its Payload property is declared as object, so the dictionary payload is typed. The nested list uses $values because typed collections are represented as objects with metadata plus values.

Swap Verification

The test suite verifies:

  • Newtonsoft round-trips through the shared serialization acceptance tests.
  • Default and custom known-type selection.
  • System.Text.Json output can be read by Newtonsoft for event messages, headers, and snapshot payloads.

The mirrored System.Text.Json tests verify the reverse direction.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 is compatible.  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 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on NEventStore.Serialization.Json:

Package Downloads
EventSaucing

An event source stack based on NEventStore and Akka

domainD.Repository.NEventStore

domainD repository implementation using NEventStore

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.2.0 101 6/15/2026
10.1.1 9,192 5/15/2025
10.1.0 1,604 4/22/2025
10.0.0 9,790 1/24/2025
9.2.0 2,721 12/23/2024
9.1.1 165,134 8/1/2023
9.0.1 138,020 12/29/2021
9.0.0 4,691 12/3/2021
8.0.0 32,789 12/18/2020
7.0.0 133,949 7/17/2019
6.1.0 4,265 7/5/2019
6.0.0 37,016 3/27/2019
6.0.0-rc-1 1,573 2/15/2019
6.0.0-rc-0 1,744 12/19/2018
4.1.0.10 107,200 9/23/2013
4.0.0.15 5,024 8/22/2013