Skip to content

Commit 22aff29

Browse files
committed
Added net10 target
1 parent 2c597d3 commit 22aff29

11 files changed

Lines changed: 124 additions & 18 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
7.x
2424
8.x
2525
9.x
26+
10.x
2627
2728
- name: dotnet build
2829
run: dotnet build

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
7.x
4949
8.x
5050
9.x
51+
10.x
5152
5253
# Initializes the CodeQL tools for scanning.
5354
- name: Initialize CodeQL

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ msbuild.err
3434
msbuild.wrn
3535

3636
# Visual Studio 2015
37-
.vs/
37+
.vs/
38+
.dotnet/

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This library tries to ease the migration from Newtonsoft.Json to System.Text.Jso
1212
similar API for HttpPatch requests as in [Microsoft.AspNetCore.JsonPatch](https://github.com/dotnet/aspnetcore/tree/main/src/Features/JsonPatch) and [Marvin.JsonPatch](https://github.com/KevinDockx/JsonPatch)
1313

1414
* Designed as an easy replacement for Microsoft.AspNetCore.JsonPatch
15-
* Supports .NET 6+ & netstandard2.0
15+
* Supports .NET 6+ including .NET 10, plus netstandard2.0
1616

1717

1818
## Getting started
@@ -79,4 +79,4 @@ WarmupCount=2
7979
|-------------------- |-----------:|-----------:|-----------:|-------:|-------:|----------:|
8080
| SystemTextJsonPatch | 3.909 us | 0.0616 us | 0.0576 us | 0.2747 | - | 4.63 KB |
8181
| MarvinJsonPatch | 741.280 us | 14.2699 us | 11.9160 us | 3.9063 | 1.9531 | 95.09 KB |
82-
| AspNetCoreJsonPatch | 15.268 us | 0.2227 us | 0.2084 us | 2.6245 | 0.0916 | 43.07 KB |
82+
| AspNetCoreJsonPatch | 15.268 us | 0.2227 us | 0.2084 us | 2.6245 | 0.0916 | 43.07 KB |

SystemTextJsonPatch.ApiTest/SystemTextJsonPatch.ApiTest.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>

SystemTextJsonPatch.Benchmark/SystemTextJsonPatch.Benchmark.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net9.0</TargetFramework>
5+
<TargetFramework>net10.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>disable</Nullable>
88
<IsPackable>false</IsPackable>
99
<IsPublishable>false</IsPublishable>
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
13+
<PackageReference Include="BenchmarkDotNet" Version="0.15.8" />
1414
<PackageReference Include="Marvin.JsonPatch" Version="2.2.1" />
15-
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="9.0.1" />
16-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
15+
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="10.0.5" />
16+
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
1717
</ItemGroup>
1818

1919
<ItemGroup>

SystemTextJsonPatch.Console/SystemTextJsonPatch.Console.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net9.0</TargetFramework>
5+
<TargetFramework>net10.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<IsPackable>false</IsPackable>
88
<IsPublishable>false</IsPublishable>

SystemTextJsonPatch.Tests/JsonPatchDocumentJsonObjectTest.cs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,48 @@ public void ReplaceJsonProp()
169169
Assert.Equal("456", prop.ToString());
170170
}
171171

172+
[Fact]
173+
public void CopyJsonProp()
174+
{
175+
var options = new JsonSerializerOptions() { };
176+
177+
var node = JsonSerializer.Deserialize<JsonObject>("{\"a\": \"12\"}");
178+
var patch = JsonSerializer.Deserialize<JsonPatchDocument>(@"[ { ""op"": ""copy"", ""path"": ""/b"", ""from"": ""/a"" } ]", options);
179+
180+
patch.ApplyTo(node);
181+
182+
node.TryGetPropertyValue("b", out var prop);
183+
184+
Assert.Equal("12", prop.ToString());
185+
}
186+
187+
[Fact]
188+
public void CopyJsonObjectProp()
189+
{
190+
var options = new JsonSerializerOptions() { };
191+
192+
var node = JsonSerializer.Deserialize<JsonObject>("{\"profile\": {\"email\": \"foo@bar.com\"}}");
193+
var patch = JsonSerializer.Deserialize<JsonPatchDocument>(@"[ { ""op"": ""copy"", ""path"": ""/profileCopy"", ""from"": ""/profile"" } ]", options);
194+
195+
patch.ApplyTo(node);
196+
197+
Assert.Equal("foo@bar.com", node["profileCopy"]["email"].GetValue<string>());
198+
}
199+
200+
[Fact]
201+
public void CopyJsonArrayProp()
202+
{
203+
var options = new JsonSerializerOptions() { };
204+
205+
var node = JsonSerializer.Deserialize<JsonObject>("{\"emails\": [\"foo@bar.com\", \"bar@baz.com\"]}");
206+
var patch = JsonSerializer.Deserialize<JsonPatchDocument>(@"[ { ""op"": ""copy"", ""path"": ""/emailsCopy"", ""from"": ""/emails"" } ]", options);
207+
208+
patch.ApplyTo(node);
209+
210+
Assert.Equal("foo@bar.com", node["emailsCopy"][0].GetValue<string>());
211+
Assert.Equal("bar@baz.com", node["emailsCopy"][1].GetValue<string>());
212+
}
213+
172214
[Fact]
173215
public void ApplyToArrayAddAndRemove()
174216
{
@@ -233,6 +275,39 @@ public void ApplyToModelCopy()
233275
Assert.Equal("foo@bar.com", model.CustomData["UserName"].GetValue<string>());
234276
}
235277

278+
[Fact]
279+
public void ApplyToModelCopyJsonObjectNode()
280+
{
281+
// Arrange
282+
var model = new ObjectWithJsonNode { CustomData = JsonSerializer.SerializeToNode(new { Profile = new { Email = "foo@bar.com" } }) };
283+
var patch = new JsonPatchDocument<ObjectWithJsonNode>();
284+
285+
patch.Operations.Add(new Operation<ObjectWithJsonNode>("copy", "/CustomData/ProfileCopy", "/CustomData/Profile"));
286+
287+
// Act
288+
patch.ApplyTo(model);
289+
290+
// Assert
291+
Assert.Equal("foo@bar.com", model.CustomData["ProfileCopy"]["Email"].GetValue<string>());
292+
}
293+
294+
[Fact]
295+
public void ApplyToModelCopyJsonArrayNode()
296+
{
297+
// Arrange
298+
var model = new ObjectWithJsonNode { CustomData = JsonSerializer.SerializeToNode(new { Emails = new[] { "foo@bar.com", "bar@baz.com" } }) };
299+
var patch = new JsonPatchDocument<ObjectWithJsonNode>();
300+
301+
patch.Operations.Add(new Operation<ObjectWithJsonNode>("copy", "/CustomData/EmailsCopy", "/CustomData/Emails"));
302+
303+
// Act
304+
patch.ApplyTo(model);
305+
306+
// Assert
307+
Assert.Equal("foo@bar.com", model.CustomData["EmailsCopy"][0].GetValue<string>());
308+
Assert.Equal("bar@baz.com", model.CustomData["EmailsCopy"][1].GetValue<string>());
309+
}
310+
236311
[Fact]
237312
public void ApplyToModelRemove()
238313
{

SystemTextJsonPatch.Tests/SystemTextJsonPatch.Tests.csproj

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net7.0;net6.0;net8.0;net9.0</TargetFrameworks>
4+
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
<IsPublishable>false</IsPublishable>
77
<IsUnitTestProject>True</IsUnitTestProject>
@@ -11,20 +11,28 @@
1111
<AnalysisLevel>8.0-all</AnalysisLevel>
1212
<EnforceCodeStyleInBuild>False</EnforceCodeStyleInBuild>
1313
<Nullable>disable</Nullable>
14+
<SuppressTfmSupportBuildErrors>true</SuppressTfmSupportBuildErrors>
1415
</PropertyGroup>
1516

1617
<ItemGroup>
1718
<PackageReference Include="JUnitTestLogger" Version="1.1.0" />
18-
<PackageReference Include="Microsoft.Net.Test.Sdk" Version="17.12.0" />
19-
<PackageReference Include="xunit" Version="2.9.3" />
19+
<PackageReference Include="Microsoft.Net.Test.Sdk" Version="18.3.0" />
2020
<!-- use latest NewtonSoft package, hides Microsoft.Net.Test.Sdk -> Microsoft.TestPlatform.TestHost refs NewtonSoft.Json >= 9.0 -->
21-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
22-
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
21+
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
22+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
2323
<PrivateAssets>all</PrivateAssets>
2424
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2525
</PackageReference>
2626
</ItemGroup>
2727

28+
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0' Or '$(TargetFramework)' == 'net7.0'">
29+
<PackageReference Include="xunit" Version="2.9.3" />
30+
</ItemGroup>
31+
32+
<ItemGroup Condition="'$(TargetFramework)' != 'net6.0' And '$(TargetFramework)' != 'net7.0'">
33+
<PackageReference Include="xunit.v3" Version="3.2.2" />
34+
</ItemGroup>
35+
2836
<ItemGroup>
2937
<ProjectReference Include="..\SystemTextJsonPatch\SystemTextJsonPatch.csproj" />
3038
</ItemGroup>

SystemTextJsonPatch/Internal/ConversionResultProvider.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ internal static bool TryCopyTo(object? value, Type typeToConvertTo, JsonSerializ
7070
return true;
7171
}
7272

73+
#if NET10_0_OR_GREATER
74+
if (value is JsonNode jsonNode)
75+
{
76+
convertedValue = jsonNode.DeepClone();
77+
return true;
78+
}
79+
#endif
80+
81+
if (value is JsonElement jsonElement)
82+
{
83+
convertedValue = jsonElement.Clone();
84+
return true;
85+
}
86+
87+
if (value is JsonDocument jsonDocument)
88+
{
89+
convertedValue = JsonDocument.Parse(jsonDocument.RootElement.GetRawText());
90+
return true;
91+
}
92+
7393
if (typeToConvertTo.IsInstanceOfType(value))
7494
{
7595
// Keep original type
@@ -92,7 +112,7 @@ internal static bool TryCopyTo(object? value, Type typeToConvertTo, JsonSerializ
92112

93113
try
94114
{
95-
convertedValue = Deserialize(value, typeToConvertTo, options);
115+
convertedValue = Deserialize(value, targetType, options);
96116

97117
return true;
98118
}

0 commit comments

Comments
 (0)