Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Upgrade to .NET 8 #43

Merged
merged 9 commits into from
Jan 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
build-configuration: [ Debug, Release ]
test-target-framework: [ net6.0, net5.0, netcoreapp3.1 ]
test-target-framework: [ net8.0, net7.0, net6.0 ]
name: Build And Test (${{ matrix.test-target-framework }}, ${{ matrix.build-configuration }})
runs-on: ubuntu-latest
steps:
@@ -20,9 +20,9 @@ jobs:
uses: actions/setup-dotnet@v2
with:
dotnet-version: |
8.x
7.x
6.x
5.x
3.1.x
- name: Restore
run: dotnet restore ${{ env.JsonDiffPatchSolutionPath }}
- name: Build
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -8,13 +8,12 @@ High-performance, low-allocating JSON object diff and patch extension for System

- Compatible with [jsondiffpatch delta format](https://github.com/benjamine/jsondiffpatch/blob/master/docs/deltas.md)
- Support generating patch document in RFC 6902 JSON Patch format
- Target latest **.NET Standard** and **.NET Framework 4.6.1** (for legacy apps) and leverage latest .NET features
- Support .NET and .NET Framework
- Alternative to [jsondiffpatch.net](https://github.com/wbish/jsondiffpatch.net) which is based on Newtonsoft.Json
- Fast large JSON document diffing with less memory consumption (see [benchmark](https://github.com/weichch/system-text-json-jsondiffpatch/blob/main/Benchmark.md))
- Support smart array diffing (e.g. move detect) using LCS (Longest Common Subsequence) and custom array item matcher
- _(Only when not using RFC 6902 format)_ Support diffing long text using [google-diff-match-patch](http://code.google.com/p/google-diff-match-patch/), or write your own diff algorithm
- Bonus `DeepEquals` method for comparing `JsonDocument`, `JsonElement` and `JsonNode`
- Bonus `DeepClone` method
- Bonus [`JsonValueComparer`](https://github.com/weichch/system-text-json-jsondiffpatch/blob/main/src/SystemTextJson.JsonDiffPatch/JsonValueComparer.cs) that implements semantic comparison of two `JsonValue` objects
- JSON assert for xUnit, MSTest v2 and NUnit with customizable delta output

@@ -44,7 +43,7 @@ PM> Install-Package SystemTextJson.JsonDiffPatch.MSTest
PM> Install-Package SystemTextJson.JsonDiffPatch.NUnit
```

## Usage
## Examples

### Diff

@@ -106,13 +105,6 @@ var textEqual = node1.DeepEquals(node2, JsonElementComparison.RawText);
var semanticEqual = node1.DeepEquals(node2, JsonElementComparison.Semantic);
```

### DeepClone

```csharp
var node = JsonNode.Parse("{\"foo\":\"bar\"}");
var cloned = node.DeepClone();
```

### Default Options

```csharp
13 changes: 13 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Release Notes

## 2.0.0

- This version contains several **BREAKING CHANGES**:
- **Targeting framework changes**:
- Added: .NET 8, .NET 7, .NET 6, .NET Framework 4.6.2
- Removed: .NET Standard 2.1, .NET Framework 4.6.1
- Minimum version of `System.Text.Json` required is bumped up to `8.0.0`
- `JsonDiffPatcher.DeepEquals(JsonNode)` now simply calls `JsonNode.DeepEquals(JsonNode, JsonNode)` method introduced in [this issue](https://github.com/dotnet/runtime/issues/56592)
- `JsonDiffPatcher.Diff` method is unchanged because it does not use `JsonNode.DeepEquals(JsonNode, JsonNode)` method internally
- You can still use `JsonDiffPatcher.DeepEquals` method when invoked with custom comparison options
- When invoked against `JsonDocument` and `JsonElement`, `DeepEquals` method is unchanged
- Removed `JsonDiffPatcher.DeepClone` method. You can migrate to `JsonNode.DeepClone` method introduced in [this issue](https://github.com/dotnet/runtime/issues/56592)

## 1.3.1

- Added `PropertyFilter` to `JsonDiffOptions` (#29)
4 changes: 3 additions & 1 deletion THIRD-PARTY-NOTICES.txt
Original file line number Diff line number Diff line change
@@ -2,7 +2,9 @@ system-text-json-jsondiffpatch uses third-party libraries or other resources tha
distributed under licenses different than system-text-json-jsondiffpatch.

In the event that we accidentally failed to list a required notice, please
bring it to our attention. Please post an issue.
bring it to our attention.

Please post an issue at https://github.com/weichch/system-text-json-jsondiffpatch/issues

The attached notices are provided for information only.

7 changes: 4 additions & 3 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project>

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net461</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.0;net462</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>

<PropertyGroup>
<JsonDiffPatchPackageVersion>1.3.1</JsonDiffPatchPackageVersion>
<JsonDiffPatchPackageVersion>2.0.0</JsonDiffPatchPackageVersion>
<Authors>Wei Chen</Authors>
<PackageProjectUrl>https://github.com/weichch/system-text-json-jsondiffpatch</PackageProjectUrl>
<Copyright>Copyright © Wei Chen 2022</Copyright>
<Copyright>Copyright © Wei Chen 2024</Copyright>
<PackageIcon>icon.png</PackageIcon>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageReleaseNotes>https://github.com/weichch/system-text-json-jsondiffpatch/blob/$(JsonDiffPatchPackageVersion)/ReleaseNotes.md</PackageReleaseNotes>
@@ -27,6 +27,7 @@
<ItemGroup>
<None Include="..\..\icon.png" Link="Packaging\icon.png" Pack="true" PackagePath="\" />
<None Include="..\..\LICENSE" Link="Packaging\LICENSE" Pack="true" PackagePath="\" />
<None Include="..\..\THIRD-PARTY-NOTICES.txt" Link="Packaging\THIRD-PARTY-NOTICES.txt" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
14 changes: 13 additions & 1 deletion src/SystemTextJson.JsonDiffPatch.MSTest/JsonAssert.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Nodes;
using System.Text.Json.Serialization.Metadata;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace System.Text.Json.JsonDiffPatch.MsTest
@@ -8,7 +9,18 @@ namespace System.Text.Json.JsonDiffPatch.MsTest
/// </summary>
public static class JsonAssert
{
private static readonly JsonSerializerOptions SerializerOptions = new() {WriteIndented = true};
private static readonly JsonSerializerOptions SerializerOptions;

static JsonAssert()
{
SerializerOptions = new()
{
TypeInfoResolver = new DefaultJsonTypeInfoResolver(),
WriteIndented = true
};

SerializerOptions.MakeReadOnly();
}

/// <summary>
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
42 changes: 27 additions & 15 deletions src/SystemTextJson.JsonDiffPatch.NUnit/JsonAssert.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Nodes;
using System.Text.Json.Serialization.Metadata;
using NUnit.Framework;

namespace System.Text.Json.JsonDiffPatch.Nunit
@@ -8,7 +9,18 @@ namespace System.Text.Json.JsonDiffPatch.Nunit
/// </summary>
public static class JsonAssert
{
private static readonly JsonSerializerOptions SerializerOptions = new() {WriteIndented = true};
private static readonly JsonSerializerOptions SerializerOptions;

static JsonAssert()
{
SerializerOptions = new()
{
TypeInfoResolver = new DefaultJsonTypeInfoResolver(),
WriteIndented = true
};

SerializerOptions.MakeReadOnly();
}

/// <summary>
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
@@ -179,7 +191,7 @@ public static void JsonAreEqual(this Assert assert, string? expected, string? ac
/// <param name="output">Whether to print diff result.</param>
public static void JsonAreEqual(this Assert assert, string? expected, string? actual, bool output)
=> AreEqual(expected, actual, output);

/// <summary>
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
/// the ordering of members in the objects is not significant.
@@ -191,7 +203,7 @@ public static void JsonAreEqual(this Assert assert, string? expected, string? ac
public static void JsonAreEqual(this Assert assert, string? expected, string? actual,
JsonDiffOptions diffOptions)
=> AreEqual(expected, actual, diffOptions);

/// <summary>
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
/// the ordering of members in the objects is not significant.
@@ -204,7 +216,7 @@ public static void JsonAreEqual(this Assert assert, string? expected, string? ac
public static void JsonAreEqual(this Assert assert, string? expected, string? actual,
JsonDiffOptions diffOptions, bool output)
=> AreEqual(expected, actual, diffOptions, output);

/// <summary>
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
/// the ordering of members in the objects is not significant.
@@ -230,7 +242,7 @@ public static void JsonAreEqual(this Assert assert, string? expected, string? ac
JsonDiffOptions diffOptions,
Func<JsonNode, string> outputFormatter)
=> AreEqual(expected, actual, diffOptions, outputFormatter);

/// <summary>
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
/// the ordering of members in the objects is not significant.
@@ -242,7 +254,7 @@ public static void JsonAreEqual(this Assert assert, string? expected, string? ac
public static void JsonAreEqual<T>(this Assert assert, T? expected, T? actual)
where T : JsonNode
=> AreEqual(expected, actual);

/// <summary>
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
/// the ordering of members in the objects is not significant.
@@ -255,7 +267,7 @@ public static void JsonAreEqual<T>(this Assert assert, T? expected, T? actual)
public static void JsonAreEqual<T>(this Assert assert, T? expected, T? actual, bool output)
where T : JsonNode
=> AreEqual(expected, actual, output);

/// <summary>
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
/// the ordering of members in the objects is not significant.
@@ -268,7 +280,7 @@ public static void JsonAreEqual<T>(this Assert assert, T? expected, T? actual, b
public static void JsonAreEqual<T>(this Assert assert, T? expected, T? actual, JsonDiffOptions diffOptions)
where T : JsonNode
=> AreEqual(expected, actual, diffOptions);

/// <summary>
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
/// the ordering of members in the objects is not significant.
@@ -283,7 +295,7 @@ public static void JsonAreEqual<T>(this Assert assert, T? expected, T? actual,
JsonDiffOptions diffOptions, bool output)
where T : JsonNode
=> AreEqual(expected, actual, diffOptions, output);

/// <summary>
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
/// the ordering of members in the objects is not significant.
@@ -378,7 +390,7 @@ public static void AreNotEqual(string? expected, string? actual)
public static void AreNotEqual(string? expected, string? actual, JsonDiffOptions diffOptions)
=> AreNotEqual(expected is null ? null : JsonNode.Parse(expected),
actual is null ? null : JsonNode.Parse(actual), diffOptions);

/// <summary>
/// Tests whether two JSON objects are not equal. Note that when comparing the specified objects,
/// the ordering of members in the objects is not significant.
@@ -389,7 +401,7 @@ public static void AreNotEqual(string? expected, string? actual, JsonDiffOptions
public static void AreNotEqual<T>(T? expected, T? actual)
where T : JsonNode
=> HandleAreNotEqual(expected, actual, null);

/// <summary>
/// Tests whether two JSON objects are not equal. Note that when comparing the specified objects,
/// the ordering of members in the objects is not significant.
@@ -402,7 +414,7 @@ public static void AreNotEqual<T>(T? expected, T? actual, JsonDiffOptions diffOp
where T : JsonNode
=> HandleAreNotEqual(expected, actual,
diffOptions ?? throw new ArgumentNullException(nameof(diffOptions)));

/// <summary>
/// Tests whether two JSON objects are not equal. Note that when comparing the specified objects,
/// the ordering of members in the objects is not significant.
@@ -412,7 +424,7 @@ public static void AreNotEqual<T>(T? expected, T? actual, JsonDiffOptions diffOp
/// <param name="actual">The actual value.</param>
public static void JsonAreNotEqual(this Assert assert, string? expected, string? actual)
=> AreNotEqual(expected, actual);

/// <summary>
/// Tests whether two JSON objects are not equal. Note that when comparing the specified objects,
/// the ordering of members in the objects is not significant.
@@ -424,7 +436,7 @@ public static void JsonAreNotEqual(this Assert assert, string? expected, string?
public static void JsonAreNotEqual(this Assert assert, string? expected, string? actual,
JsonDiffOptions diffOptions)
=> AreNotEqual(expected, actual, diffOptions);

/// <summary>
/// Tests whether two JSON objects are not equal. Note that when comparing the specified objects,
/// the ordering of members in the objects is not significant.
@@ -436,7 +448,7 @@ public static void JsonAreNotEqual(this Assert assert, string? expected, string?
public static void JsonAreNotEqual<T>(this Assert assert, T? expected, T? actual)
where T : JsonNode
=> AreNotEqual(expected, actual);

/// <summary>
/// Tests whether two JSON objects are not equal. Note that when comparing the specified objects,
/// the ordering of members in the objects is not significant.
14 changes: 13 additions & 1 deletion src/SystemTextJson.JsonDiffPatch.Xunit/JsonAssert.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Nodes;
using System.Text.Json.Serialization.Metadata;

namespace System.Text.Json.JsonDiffPatch.Xunit
{
@@ -7,7 +8,18 @@ namespace System.Text.Json.JsonDiffPatch.Xunit
/// </summary>
public static class JsonAssert
{
private static readonly JsonSerializerOptions SerializerOptions = new() {WriteIndented = true};
private static readonly JsonSerializerOptions SerializerOptions;

static JsonAssert()
{
SerializerOptions = new()
{
TypeInfoResolver = new DefaultJsonTypeInfoResolver(),
WriteIndented = true
};

SerializerOptions.MakeReadOnly();
}

/// <summary>
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
8 changes: 4 additions & 4 deletions src/SystemTextJson.JsonDiffPatch/Diffs/JsonDiffDelta.cs
Original file line number Diff line number Diff line change
@@ -244,22 +244,22 @@ public void Added(JsonNode? newValue)
{
EnsureDeltaType(nameof(Added), count: 1);
var arr = Document!.AsArray();
arr[0] = newValue.DeepClone();
arr[0] = newValue?.DeepClone();
}

public void Modified(JsonNode? oldValue, JsonNode? newValue)
{
EnsureDeltaType(nameof(Modified), count: 2);
var arr = Document!.AsArray();
arr[0] = oldValue.DeepClone();
arr[1] = newValue.DeepClone();
arr[0] = oldValue?.DeepClone();
arr[1] = newValue?.DeepClone();
}

public void Deleted(JsonNode? oldValue)
{
EnsureDeltaType(nameof(Deleted), count: 3, opType: OpTypeDeleted);
var arr = Document!.AsArray();
arr[0] = oldValue.DeepClone();
arr[0] = oldValue?.DeepClone();
arr[1] = 0;
}

Loading