Skip to content

Commit e919acf

Browse files
weichchmatracey
andauthored
Upgrade to .NET 8 (#43)
* Upgraded to .NET 8 Co-authored-by: Martin Tracey <1207505+matracey@users.noreply.github.com>
1 parent 0d4a3ad commit e919acf

File tree

24 files changed

+152
-227
lines changed

24 files changed

+152
-227
lines changed

.github/workflows/build-and-test.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
matrix:
1313
build-configuration: [ Debug, Release ]
14-
test-target-framework: [ net6.0, net5.0, netcoreapp3.1 ]
14+
test-target-framework: [ net8.0, net7.0, net6.0 ]
1515
name: Build And Test (${{ matrix.test-target-framework }}, ${{ matrix.build-configuration }})
1616
runs-on: ubuntu-latest
1717
steps:
@@ -20,9 +20,9 @@ jobs:
2020
uses: actions/setup-dotnet@v2
2121
with:
2222
dotnet-version: |
23+
8.x
24+
7.x
2325
6.x
24-
5.x
25-
3.1.x
2626
- name: Restore
2727
run: dotnet restore ${{ env.JsonDiffPatchSolutionPath }}
2828
- name: Build

README.md

+2-10
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ High-performance, low-allocating JSON object diff and patch extension for System
88

99
- Compatible with [jsondiffpatch delta format](https://github.com/benjamine/jsondiffpatch/blob/master/docs/deltas.md)
1010
- Support generating patch document in RFC 6902 JSON Patch format
11-
- Target latest **.NET Standard** and **.NET Framework 4.6.1** (for legacy apps) and leverage latest .NET features
11+
- Support .NET and .NET Framework
1212
- Alternative to [jsondiffpatch.net](https://github.com/wbish/jsondiffpatch.net) which is based on Newtonsoft.Json
1313
- Fast large JSON document diffing with less memory consumption (see [benchmark](https://github.com/weichch/system-text-json-jsondiffpatch/blob/main/Benchmark.md))
1414
- Support smart array diffing (e.g. move detect) using LCS (Longest Common Subsequence) and custom array item matcher
1515
- _(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
1616
- Bonus `DeepEquals` method for comparing `JsonDocument`, `JsonElement` and `JsonNode`
17-
- Bonus `DeepClone` method
1817
- 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
1918
- JSON assert for xUnit, MSTest v2 and NUnit with customizable delta output
2019

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

47-
## Usage
46+
## Examples
4847

4948
### Diff
5049

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

109-
### DeepClone
110-
111-
```csharp
112-
var node = JsonNode.Parse("{\"foo\":\"bar\"}");
113-
var cloned = node.DeepClone();
114-
```
115-
116108
### Default Options
117109

118110
```csharp

ReleaseNotes.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Release Notes
22

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

518
- Added `PropertyFilter` to `JsonDiffOptions` (#29)

THIRD-PARTY-NOTICES.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ system-text-json-jsondiffpatch uses third-party libraries or other resources tha
22
distributed under licenses different than system-text-json-jsondiffpatch.
33

44
In the event that we accidentally failed to list a required notice, please
5-
bring it to our attention. Please post an issue.
5+
bring it to our attention.
6+
7+
Please post an issue at https://github.com/weichch/system-text-json-jsondiffpatch/issues
68

79
The attached notices are provided for information only.
810

src/Directory.Build.props

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<Project>
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;netstandard2.1;net461</TargetFrameworks>
4+
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.0;net462</TargetFrameworks>
55
<Nullable>enable</Nullable>
66
<LangVersion>latest</LangVersion>
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>
88
<NoWarn>$(NoWarn);CS1591</NoWarn>
99
</PropertyGroup>
1010

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

3233
</Project>

src/SystemTextJson.JsonDiffPatch.MSTest/JsonAssert.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text.Json.Nodes;
2+
using System.Text.Json.Serialization.Metadata;
23
using Microsoft.VisualStudio.TestTools.UnitTesting;
34

45
namespace System.Text.Json.JsonDiffPatch.MsTest
@@ -8,7 +9,18 @@ namespace System.Text.Json.JsonDiffPatch.MsTest
89
/// </summary>
910
public static class JsonAssert
1011
{
11-
private static readonly JsonSerializerOptions SerializerOptions = new() {WriteIndented = true};
12+
private static readonly JsonSerializerOptions SerializerOptions;
13+
14+
static JsonAssert()
15+
{
16+
SerializerOptions = new()
17+
{
18+
TypeInfoResolver = new DefaultJsonTypeInfoResolver(),
19+
WriteIndented = true
20+
};
21+
22+
SerializerOptions.MakeReadOnly();
23+
}
1224

1325
/// <summary>
1426
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,

src/SystemTextJson.JsonDiffPatch.NUnit/JsonAssert.cs

+27-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text.Json.Nodes;
2+
using System.Text.Json.Serialization.Metadata;
23
using NUnit.Framework;
34

45
namespace System.Text.Json.JsonDiffPatch.Nunit
@@ -8,7 +9,18 @@ namespace System.Text.Json.JsonDiffPatch.Nunit
89
/// </summary>
910
public static class JsonAssert
1011
{
11-
private static readonly JsonSerializerOptions SerializerOptions = new() {WriteIndented = true};
12+
private static readonly JsonSerializerOptions SerializerOptions;
13+
14+
static JsonAssert()
15+
{
16+
SerializerOptions = new()
17+
{
18+
TypeInfoResolver = new DefaultJsonTypeInfoResolver(),
19+
WriteIndented = true
20+
};
21+
22+
SerializerOptions.MakeReadOnly();
23+
}
1224

1325
/// <summary>
1426
/// 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
179191
/// <param name="output">Whether to print diff result.</param>
180192
public static void JsonAreEqual(this Assert assert, string? expected, string? actual, bool output)
181193
=> AreEqual(expected, actual, output);
182-
194+
183195
/// <summary>
184196
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
185197
/// 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
191203
public static void JsonAreEqual(this Assert assert, string? expected, string? actual,
192204
JsonDiffOptions diffOptions)
193205
=> AreEqual(expected, actual, diffOptions);
194-
206+
195207
/// <summary>
196208
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
197209
/// 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
204216
public static void JsonAreEqual(this Assert assert, string? expected, string? actual,
205217
JsonDiffOptions diffOptions, bool output)
206218
=> AreEqual(expected, actual, diffOptions, output);
207-
219+
208220
/// <summary>
209221
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
210222
/// 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
230242
JsonDiffOptions diffOptions,
231243
Func<JsonNode, string> outputFormatter)
232244
=> AreEqual(expected, actual, diffOptions, outputFormatter);
233-
245+
234246
/// <summary>
235247
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
236248
/// 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
242254
public static void JsonAreEqual<T>(this Assert assert, T? expected, T? actual)
243255
where T : JsonNode
244256
=> AreEqual(expected, actual);
245-
257+
246258
/// <summary>
247259
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
248260
/// 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)
255267
public static void JsonAreEqual<T>(this Assert assert, T? expected, T? actual, bool output)
256268
where T : JsonNode
257269
=> AreEqual(expected, actual, output);
258-
270+
259271
/// <summary>
260272
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
261273
/// 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
268280
public static void JsonAreEqual<T>(this Assert assert, T? expected, T? actual, JsonDiffOptions diffOptions)
269281
where T : JsonNode
270282
=> AreEqual(expected, actual, diffOptions);
271-
283+
272284
/// <summary>
273285
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
274286
/// 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,
283295
JsonDiffOptions diffOptions, bool output)
284296
where T : JsonNode
285297
=> AreEqual(expected, actual, diffOptions, output);
286-
298+
287299
/// <summary>
288300
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,
289301
/// the ordering of members in the objects is not significant.
@@ -378,7 +390,7 @@ public static void AreNotEqual(string? expected, string? actual)
378390
public static void AreNotEqual(string? expected, string? actual, JsonDiffOptions diffOptions)
379391
=> AreNotEqual(expected is null ? null : JsonNode.Parse(expected),
380392
actual is null ? null : JsonNode.Parse(actual), diffOptions);
381-
393+
382394
/// <summary>
383395
/// Tests whether two JSON objects are not equal. Note that when comparing the specified objects,
384396
/// the ordering of members in the objects is not significant.
@@ -389,7 +401,7 @@ public static void AreNotEqual(string? expected, string? actual, JsonDiffOptions
389401
public static void AreNotEqual<T>(T? expected, T? actual)
390402
where T : JsonNode
391403
=> HandleAreNotEqual(expected, actual, null);
392-
404+
393405
/// <summary>
394406
/// Tests whether two JSON objects are not equal. Note that when comparing the specified objects,
395407
/// 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
402414
where T : JsonNode
403415
=> HandleAreNotEqual(expected, actual,
404416
diffOptions ?? throw new ArgumentNullException(nameof(diffOptions)));
405-
417+
406418
/// <summary>
407419
/// Tests whether two JSON objects are not equal. Note that when comparing the specified objects,
408420
/// 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
412424
/// <param name="actual">The actual value.</param>
413425
public static void JsonAreNotEqual(this Assert assert, string? expected, string? actual)
414426
=> AreNotEqual(expected, actual);
415-
427+
416428
/// <summary>
417429
/// Tests whether two JSON objects are not equal. Note that when comparing the specified objects,
418430
/// the ordering of members in the objects is not significant.
@@ -424,7 +436,7 @@ public static void JsonAreNotEqual(this Assert assert, string? expected, string?
424436
public static void JsonAreNotEqual(this Assert assert, string? expected, string? actual,
425437
JsonDiffOptions diffOptions)
426438
=> AreNotEqual(expected, actual, diffOptions);
427-
439+
428440
/// <summary>
429441
/// Tests whether two JSON objects are not equal. Note that when comparing the specified objects,
430442
/// the ordering of members in the objects is not significant.
@@ -436,7 +448,7 @@ public static void JsonAreNotEqual(this Assert assert, string? expected, string?
436448
public static void JsonAreNotEqual<T>(this Assert assert, T? expected, T? actual)
437449
where T : JsonNode
438450
=> AreNotEqual(expected, actual);
439-
451+
440452
/// <summary>
441453
/// Tests whether two JSON objects are not equal. Note that when comparing the specified objects,
442454
/// the ordering of members in the objects is not significant.

src/SystemTextJson.JsonDiffPatch.Xunit/JsonAssert.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text.Json.Nodes;
2+
using System.Text.Json.Serialization.Metadata;
23

34
namespace System.Text.Json.JsonDiffPatch.Xunit
45
{
@@ -7,7 +8,18 @@ namespace System.Text.Json.JsonDiffPatch.Xunit
78
/// </summary>
89
public static class JsonAssert
910
{
10-
private static readonly JsonSerializerOptions SerializerOptions = new() {WriteIndented = true};
11+
private static readonly JsonSerializerOptions SerializerOptions;
12+
13+
static JsonAssert()
14+
{
15+
SerializerOptions = new()
16+
{
17+
TypeInfoResolver = new DefaultJsonTypeInfoResolver(),
18+
WriteIndented = true
19+
};
20+
21+
SerializerOptions.MakeReadOnly();
22+
}
1123

1224
/// <summary>
1325
/// Tests whether two JSON objects are equal. Note that when comparing the specified objects,

src/SystemTextJson.JsonDiffPatch/Diffs/JsonDiffDelta.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,22 @@ public void Added(JsonNode? newValue)
244244
{
245245
EnsureDeltaType(nameof(Added), count: 1);
246246
var arr = Document!.AsArray();
247-
arr[0] = newValue.DeepClone();
247+
arr[0] = newValue?.DeepClone();
248248
}
249249

250250
public void Modified(JsonNode? oldValue, JsonNode? newValue)
251251
{
252252
EnsureDeltaType(nameof(Modified), count: 2);
253253
var arr = Document!.AsArray();
254-
arr[0] = oldValue.DeepClone();
255-
arr[1] = newValue.DeepClone();
254+
arr[0] = oldValue?.DeepClone();
255+
arr[1] = newValue?.DeepClone();
256256
}
257257

258258
public void Deleted(JsonNode? oldValue)
259259
{
260260
EnsureDeltaType(nameof(Deleted), count: 3, opType: OpTypeDeleted);
261261
var arr = Document!.AsArray();
262-
arr[0] = oldValue.DeepClone();
262+
arr[0] = oldValue?.DeepClone();
263263
arr[1] = 0;
264264
}
265265

0 commit comments

Comments
 (0)