Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Havunen/SystemTextJsonPatch
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.0.0
Choose a base ref
...
head repository: Havunen/SystemTextJsonPatch
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Aug 14, 2023

  1. Update README.md

    Sampo Kivistö authored Aug 14, 2023
    Copy the full SHA
    f6df1c1 View commit details

Commits on Aug 21, 2023

  1. All invalid patch operations now correctly throw JsonPatchTestOperati…

    …onException and malformed patch documents throw JsonPatchException
    Havunen committed Aug 21, 2023
    Copy the full SHA
    f3b1341 View commit details
  2. v3.0.1

    Havunen committed Aug 21, 2023
    Copy the full SHA
    344f32c View commit details
  3. Bump Miccrosoft.Net.Test.SDK

    Havunen committed Aug 21, 2023
    Copy the full SHA
    652e578 View commit details
  4. Copy the full SHA
    c235a99 View commit details
  5. Copy the full SHA
    9e01971 View commit details
  6. ignore net48

    Havunen committed Aug 21, 2023
    Copy the full SHA
    e9dad69 View commit details

Commits on Nov 14, 2023

  1. Copy the full SHA
    78cc980 View commit details
  2. v3.1.0

    Havunen committed Nov 14, 2023
    Copy the full SHA
    4fda18c View commit details
  3. Added .NET 8 to CI

    Havunen committed Nov 14, 2023
    Copy the full SHA
    9acc02c View commit details

Commits on Apr 13, 2024

  1. Updated dependencies

    Havunen committed Apr 13, 2024
    Copy the full SHA
    c7d5c55 View commit details
  2. Copy the full SHA
    67651b7 View commit details

Commits on May 30, 2024

  1. Copy the full SHA
    737387e View commit details
  2. Let DictionaryTypedPropertyProxy be generic to support adding to a di…

    …ctionary with a given value type
    rmja committed May 30, 2024
    Copy the full SHA
    0596276 View commit details
  3. Copy the full SHA
    41fd1f5 View commit details
  4. Copy the full SHA
    5bb2d6c View commit details
  5. Merge pull request #29 from rmja/generic-dictionary

    Fix issue when adding a new complex value to a generic dictionary
    Havunen authored May 30, 2024
    Copy the full SHA
    e00dfc2 View commit details
  6. Copy the full SHA
    540012e View commit details
  7. v3.2.0

    Havunen committed May 30, 2024
    Copy the full SHA
    ab492ce View commit details

Commits on Aug 7, 2024

  1. Updated dependencies

    Havunen committed Aug 7, 2024
    Copy the full SHA
    e18495c View commit details
  2. Copy the full SHA
    06aaa85 View commit details
  3. Copy the full SHA
    ac8a0be View commit details
  4. Copy the full SHA
    f63db79 View commit details
  5. Added the fix to changelog #31

    Havunen committed Aug 7, 2024
    Copy the full SHA
    cbea188 View commit details
  6. Copy the full SHA
    68c19c9 View commit details
  7. v3.2.1

    Havunen committed Aug 7, 2024
    Copy the full SHA
    d8576a6 View commit details

Commits on Oct 4, 2024

  1. Copy the full SHA
    298e378 View commit details
  2. Copy the full SHA
    7b2ff47 View commit details
  3. Copy the full SHA
    a00db29 View commit details
  4. Copy the full SHA
    2e4bb61 View commit details
  5. Added unit tests

    AnderssonPeter committed Oct 4, 2024
    Copy the full SHA
    10fe7ee View commit details
  6. Copy the full SHA
    cdcdb56 View commit details
  7. Merge pull request #34 from AnderssonPeter/main

    Add deny access functionality
    Havunen authored Oct 4, 2024
    Copy the full SHA
    7fc8215 View commit details

Commits on Oct 5, 2024

  1. Updated dependencies

    Havunen committed Oct 5, 2024
    Copy the full SHA
    c6aa5d0 View commit details
  2. v3.3.0

    Havunen committed Oct 5, 2024
    Copy the full SHA
    847bb2a View commit details

Commits on Oct 11, 2024

  1. Add snake case test

    sguryev committed Oct 11, 2024
    Copy the full SHA
    df190f9 View commit details

Commits on Oct 18, 2024

  1. Merge pull request #35 from sguryev/serj/main-snake-test

    Add snake case test
    Havunen authored Oct 18, 2024
    Copy the full SHA
    17bfc79 View commit details
  2. Use generic overload

    Havunen committed Oct 18, 2024
    Copy the full SHA
    a888c60 View commit details
  3. breaking change: Changed property matching to follow more closely Sys…

    …tem.Text.Json naming policy. Fixes #36
    Havunen committed Oct 18, 2024
    Copy the full SHA
    3554f1c View commit details
  4. updated deps

    Havunen committed Oct 18, 2024
    Copy the full SHA
    240addd View commit details
  5. Removed NotSupportedException and InvalidOperationException to reduce…

    … different exception types.
    Havunen committed Oct 18, 2024
    Copy the full SHA
    98cacad View commit details
  6. Breaking change: Refactored exception types JsonPatchException now co…

    …ntains FailedOperation information and JsonPatchTestOperationException is thrown only for test -operation failures
    Havunen committed Oct 18, 2024
    Copy the full SHA
    ef1852f View commit details
  7. Added example web api

    Havunen committed Oct 18, 2024
    Copy the full SHA
    f61fd2c View commit details
  8. 4.0.0

    Havunen committed Oct 18, 2024
    Copy the full SHA
    2e496ef View commit details

Commits on Nov 15, 2024

  1. Improve readme for #37

    Havunen committed Nov 15, 2024
    Copy the full SHA
    19e8a82 View commit details
  2. added .NET 9 support

    Havunen committed Nov 15, 2024
    Copy the full SHA
    1339957 View commit details
  3. 4.1.0

    Havunen committed Nov 15, 2024
    Copy the full SHA
    ae4452f View commit details
  4. Update codeql-analysis.yml

    Havunen authored Nov 15, 2024
    Copy the full SHA
    a7434e9 View commit details

Commits on Jan 16, 2025

  1. Respect PropertyNameCaseInsensitive setting (#42)

    * Respect PropertyNameCaseInsensitive setting
    
    * Check in JsonPropertyNameAttribute also
    
    * Fix test
    
    * Respect PropertyNameCaseInsensitive setting in JsonObjects also
    twenzel authored Jan 16, 2025
    Copy the full SHA
    b7cf008 View commit details

Commits on Jan 17, 2025

  1. Handle KeyNotFoundException thrown from DictionaryPropertyProxy and D…

    …ictionaryTypedPropertyProxy (#40)
    
    * handle KeyNotFoundException thrown from DictionaryPropertyProxy and DictionaryTypedPropertyProxy
    
    * use TryGetValue in DictionaryTypedPropertyProxy
    
    * remove try-catch in DictionaryPropertyProxy
    
    * revert to stopping patch execution on patch error
    sbiot-aveva authored Jan 17, 2025
    Copy the full SHA
    ea4baf5 View commit details
Showing with 1,222 additions and 205 deletions.
  1. +2 −0 .editorconfig
  2. +4 −3 .github/workflows/ci.yml
  3. +9 −0 .github/workflows/codeql-analysis.yml
  4. +45 −0 CHANGELOG.md
  5. +16 −11 README.md
  6. +62 −0 SystemTextJsonPatch.ApiTest/Controllers/WeatherController.cs
  7. +12 −0 SystemTextJsonPatch.ApiTest/Program.cs
  8. +25 −0 SystemTextJsonPatch.ApiTest/Properties/launchSettings.json
  9. +13 −0 SystemTextJsonPatch.ApiTest/SystemTextJsonPatch.ApiTest.csproj
  10. +8 −0 SystemTextJsonPatch.ApiTest/appsettings.Development.json
  11. +9 −0 SystemTextJsonPatch.ApiTest/appsettings.json
  12. +12 −8 SystemTextJsonPatch.Benchmark/Benchmarks/DeserializeAndApplyToBenchmark.cs
  13. +3 −3 SystemTextJsonPatch.Benchmark/SystemTextJsonPatch.Benchmark.csproj
  14. +8 −8 SystemTextJsonPatch.Console/DeserializeTest.cs
  15. +1 −1 SystemTextJsonPatch.Console/SystemTextJsonPatch.Console.csproj
  16. +26 −0 SystemTextJsonPatch.Tests/ExceptionTests.cs
  17. +4 −2 SystemTextJsonPatch.Tests/IntegrationTests/AnonymousObjectIntegrationTest.cs
  18. +2 −0 SystemTextJsonPatch.Tests/IntegrationTests/CustomConverterErrorMessagesTest.cs
  19. +1 −0 SystemTextJsonPatch.Tests/IntegrationTests/DecimalComparisonTest.cs
  20. +94 −0 SystemTextJsonPatch.Tests/IntegrationTests/DenyIntegrationTest.cs
  21. +218 −30 SystemTextJsonPatch.Tests/IntegrationTests/DictionaryIntegrationTest.cs
  22. +1 −1 SystemTextJsonPatch.Tests/IntegrationTests/DynamicObjectIntegrationTest.cs
  23. +2 −1 SystemTextJsonPatch.Tests/IntegrationTests/ErrorMessageTest.cs
  24. +23 −23 SystemTextJsonPatch.Tests/IntegrationTests/ExpandoObjectIntegrationTest.cs
  25. +2 −2 SystemTextJsonPatch.Tests/IntegrationTests/ListIntegrationTest.cs
  26. +128 −0 SystemTextJsonPatch.Tests/IntegrationTests/NestedObjectIntegrationTest.cs
  27. +18 −0 SystemTextJsonPatch.Tests/IntegrationTests/PatchDocumentSerializationTest.cs
  28. +50 −0 SystemTextJsonPatch.Tests/IntegrationTests/SimpleObjectIntegrationTest.cs
  29. +57 −0 SystemTextJsonPatch.Tests/IntegrationTests/TestOperationIntegrationTests.cs
  30. +2 −1 SystemTextJsonPatch.Tests/JsonPatchDocumentGetPathTest.cs
  31. +33 −1 SystemTextJsonPatch.Tests/JsonPatchDocumentJsonObjectTest.cs
  32. +5 −5 SystemTextJsonPatch.Tests/SystemTextJsonPatch.Tests.csproj
  33. +41 −0 SystemTextJsonPatch.Tests/TestObjectModels/NonGenericDictionary.cs
  34. +21 −0 SystemTextJsonPatch.Tests/TestObjectModels/PropertyNameCasingTestObject.cs
  35. +28 −0 SystemTextJsonPatch.Tests/TestObjectModels/SimpleObjectWithDeny.cs
  36. +28 −0 SystemTextJsonPatch.Tests/TestObjectModels/SimpleObjectWithNestedObjectAndDeny.cs
  37. +7 −0 SystemTextJsonPatch.sln
  38. +4 −2 SystemTextJsonPatch/Adapters/ObjectAdapter.cs
  39. +4 −2 SystemTextJsonPatch/Converters/JsonPatchDocumentConverterFactory.cs
  40. +9 −0 SystemTextJsonPatch/DenyPatchAttribute.cs
  41. +4 −12 SystemTextJsonPatch/Exceptions/ExceptionHelper.cs
  42. +32 −0 SystemTextJsonPatch/Exceptions/JsonPatchAccessDeniedException.cs
  43. +5 −2 SystemTextJsonPatch/Exceptions/JsonPatchException.cs
  44. +1 −13 SystemTextJsonPatch/Exceptions/JsonPatchTestOperationException.cs
  45. +19 −0 SystemTextJsonPatch/Internal/ByteHelper.cs
  46. +2 −1 SystemTextJsonPatch/Internal/ErrorReporter.cs
  47. +37 −15 SystemTextJsonPatch/Internal/JSonObjectAdapter.cs
  48. +1 −2 SystemTextJsonPatch/Internal/ListAdapter.cs
  49. +25 −8 SystemTextJsonPatch/Internal/PocoAdapter.cs
  50. +24 −7 SystemTextJsonPatch/Internal/PropertyProxyCache.cs
  51. +10 −4 SystemTextJsonPatch/Internal/Proxies/DictionaryPropertyProxy.cs
  52. +16 −22 SystemTextJsonPatch/Internal/Proxies/DictionaryTypedPropertyProxy.cs
  53. +1 −1 SystemTextJsonPatch/JsonPatchDocumentOfT.cs
  54. +1 −1 SystemTextJsonPatch/Operations/Operation.cs
  55. +1 −1 SystemTextJsonPatch/Operations/OperationOfT.cs
  56. +0 −6 SystemTextJsonPatch/Resources.Designer.cs
  57. +6 −6 SystemTextJsonPatch/SystemTextJsonPatch.csproj
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.cs]
indent_style = tab
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -19,9 +19,10 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
3.1.x
5.0.x
6.0.x
6.x
7.x
8.x
9.x
- name: dotnet build
run: dotnet build
9 changes: 9 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -40,6 +40,15 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.x
7.x
8.x
9.x
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
45 changes: 45 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
## 4.2.0

- Correctly handle key not found exception when applying patch document to dictionary https://github.com/Havunen/SystemTextJsonPatch/pull/40
- Respect STJ options PropertyNameCaseInsensitive setting https://github.com/Havunen/SystemTextJsonPatch/pull/42
- Internal dependencies updated

## 4.1.0

- Adds .NET 9 support

## 4.0.0

**BREAKING CHANGE:** SystemTextJsonPatch now supports different property naming policies!
f.e. `JsonNamingPolicy.SnakeCaseLower`. Fixes https://github.com/Havunen/SystemTextJsonPatch/issues/36

- This means that the **path** and **from** of the system text json patch document needs to match the JSON serializer options property naming policy.
For example, if the JSON serializer options are set to use camelCase, the patch path should also be in camelCase.

**BREAKING CHANGE:** Exception types have been changed.

- `JsonPatchException` -base exception type now contains `FailedOperation` and `AffectedObject` properties.
These properties are populated with the failed operation when the operation is available.
This change is to provide more information about the failed operation and the affected object. Fixes: https://github.com/Havunen/SystemTextJsonPatch/issues/26
- `NotSupportedException` and `InvalidOperationException` are not thrown anymore. Instead, `JsonPatchException` is thrown with the appropriate message.
- `JsonPatchTestOperationException` is now thrown only when the test operation fails. Fixes https://github.com/Havunen/SystemTextJsonPatch/issues/22

## 3.3.0
- Adds support for `DenyPatch` attribute to deny access to annotated property https://github.com/Havunen/SystemTextJsonPatch/pull/34
- Internal dependencies updated

## 3.2.1
- Fixes an issue where null and empty string test operation of JsonNode was incorrectly handled https://github.com/Havunen/SystemTextJsonPatch/issues/31
- Improved performance of JSON patch test operation

## 3.2.0
- Adds support for dictionary complex types https://github.com/Havunen/SystemTextJsonPatch/pull/29
- Internal dependencies updated

## 3.1.0
- Added .NET 8 target framework

## 3.0.1
- All invalid patch operations now correctly throw JsonPatchTestOperationException and malformed patch documents throw JsonPatchException


## 3.0.0
- Library runtime performance is improved by using throw helpers for throwing exceptions https://github.com/Havunen/SystemTextJsonPatch/issues/21
- **Possibly breaking change**: `JsonPatchTestOperationException` type is now thrown for `test` -operation failures https://github.com/Havunen/SystemTextJsonPatch/issues/22
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -21,7 +21,9 @@ Build a patch document on the client.
You can use the operations as described in the IETF document: Add, Remove, Replace, Copy, Move and Test.

```cs
JsonPatchDocument<DTO.Expense> expensePatch = new JsonPatchDocument<DTO.Expense>();
List<Operation<DTO.Expense>> operations = [];
JsonSerializerOptions jsonOptions = new JsonSerializerOptions();
JsonPatchDocument<DTO.Expense> expensePatch = new JsonPatchDocument<DTO.Expense>(operations, jsonOptions);
expensePatch.Replace(e => e.Description, expense.Description);

// serialize it to JSON
@@ -49,6 +51,11 @@ public IHttpActionResult Patch(
}
```

## Deny access to properties
If you need to stop JsonPatch from reading or writing to some properties,
then you can decorate them with `[DenyPatch]`, if a patch occurs that happens to access the property then a `JsonPatchAccessDeniedException` is thrown.


## Migration from v1

JsonPatchDocumentConverterFactory no longer needs to be set to JsonSerializerOptions.
@@ -60,18 +67,16 @@ This test deserializes a JSON patch document of 8 operations and applies the cha

See [SystemTextJsonPatch.Benchmark](https://github.com/Havunen/SystemTextJsonPatch/tree/main/SystemTextJsonPatch.Benchmark) for more details.

(SystemTextJsonPatch , )

BenchmarkDotNet v0.13.7, Windows 11 (10.0.22621.2134/22H2/2022Update/SunValley2)
BenchmarkDotNet v0.14.0, Windows 11 (10.0.26100.2605)
AMD Ryzen 9 5950X, 1 CPU, 32 logical and 16 physical cores
.NET SDK 8.0.100-preview.7.23376.3
[Host] : .NET 7.0.9 (7.0.923.32018), X64 RyuJIT AVX2
Job-TMETTY : .NET 7.0.9 (7.0.923.32018), X64 RyuJIT AVX2
.NET SDK 9.0.200-preview.0.24575.35
[Host] : .NET 9.0.0 (9.0.24.52809), X64 RyuJIT AVX2
Job-ZCWSQV : .NET 9.0.0 (9.0.24.52809), X64 RyuJIT AVX2

WarmupCount=2

| Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated |
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated |
|-------------------- |-----------:|-----------:|-----------:|-------:|-------:|----------:|
| SystemTextJsonPatch (v3.0.0) | 4.953 us | 0.0277 us | 0.0259 us | 0.2899 | - | 4.83 KB |
| MarvinJsonPatch (v2.2.1) | 909.176 us | 17.4292 us | 18.6490 us | 5.8594 | 3.9063 | 96.14 KB |
| AspNetCoreJsonPatch (v7.0.10) | 24.742 us | 0.3156 us | 0.2952 us | 2.6550 | 0.0610 | 43.61 KB |
| SystemTextJsonPatch | 3.909 us | 0.0616 us | 0.0576 us | 0.2747 | - | 4.63 KB |
| MarvinJsonPatch | 741.280 us | 14.2699 us | 11.9160 us | 3.9063 | 1.9531 | 95.09 KB |
| AspNetCoreJsonPatch | 15.268 us | 0.2227 us | 0.2084 us | 2.6245 | 0.0916 | 43.07 KB |
62 changes: 62 additions & 0 deletions SystemTextJsonPatch.ApiTest/Controllers/WeatherController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;

namespace SystemTextJsonPatch.ApiTest.Controllers
{
[Route("api/[controller]")]
public class WeatherController : ControllerBase
{
private readonly WeatherForecast[] _weatherForecasts = new WeatherForecast[]
{
new WeatherForecast { Date = DateTime.Now, TemperatureC = 25, Summary = "Hot" },
new WeatherForecast { Date = DateTime.Now.AddDays(1), TemperatureC = 20, Summary = "Warm" },
new WeatherForecast { Date = DateTime.Now.AddDays(2), TemperatureC = 15, Summary = "Cool" },
new WeatherForecast { Date = DateTime.Now.AddDays(3), TemperatureC = 10, Summary = "Cold" },
new WeatherForecast { Date = DateTime.Now.AddDays(4), TemperatureC = 5, Summary = "Freezing" }
};

[HttpGet]
public IActionResult GetWeather()
{
return Ok(_weatherForecasts);
}

[HttpPost]
public ActionResult<WeatherForecast> PostWeather([FromBody, Required] WeatherForecast? weatherForecast)
{
if (weatherForecast == null || ModelState.IsValid == false)
{
return ValidationProblem(this.ModelState);
}

return CreatedAtAction(nameof(GetWeather), weatherForecast);
}

[HttpPatch("{id}")]
public IActionResult PatchWeather(int id, [FromBody, Required] JsonPatchDocument<WeatherForecast>? patchDoc)
{
var weatherForecast = _weatherForecasts[id];
if (weatherForecast == null)
{
return NotFound();
}

patchDoc.ApplyTo(weatherForecast);
TryValidateModel(weatherForecast);
if (ModelState.IsValid == false)
{
return ValidationProblem(this.ModelState);
}

return Ok();
}
}

public class WeatherForecast
{
public DateTime Date { get; set; }
[Required]
public int? TemperatureC { get; set; }
public string Summary { get; set; }
}
}
12 changes: 12 additions & 0 deletions SystemTextJsonPatch.ApiTest/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();

var app = builder.Build();

app.MapControllers();
app.UseHttpsRedirection();

app.Run();
25 changes: 25 additions & 0 deletions SystemTextJsonPatch.ApiTest/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "http://localhost:5290",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "https://localhost:7027;http://localhost:5290",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
13 changes: 13 additions & 0 deletions SystemTextJsonPatch.ApiTest/SystemTextJsonPatch.ApiTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\SystemTextJsonPatch\SystemTextJsonPatch.csproj" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions SystemTextJsonPatch.ApiTest/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions SystemTextJsonPatch.ApiTest/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Original file line number Diff line number Diff line change
@@ -17,14 +17,18 @@ public void GlobalSetup()
};
}

public static string DeserializePatchDocJson = string.Format("[" + "{{\"op\": \"replace\", \"path\": \"number\", \"value\": 86632}}," +
"{{\"op\": \"replace\", \"path\": \"text\", \"value\": \"testing-performance\"}}," +
"{{\"op\": \"add\", \"path\": \"amount\", \"value\": 86632.172712}}," +
"{{\"op\": \"replace\", \"path\": \"amount2\", \"value\": null}}," +
"{{\"op\": \"replace\", \"path\": \"subTestModel\", \"value\": {{\"id\": 91117, \"data\": 78}}}}," +
"{{\"op\": \"test\", \"path\": \"number\", \"value\": 86632}}," +
"{{\"op\": \"copy\", \"path\": \"amount2\", \"from\": \"amount\"}}," +
"{{\"op\": \"remove\", \"path\": \"text\"}}" + "]");
public static string DeserializePatchDocJson = string.Format(
"[" +
"{{\"op\": \"replace\", \"path\": \"Number\", \"value\": 86632}}," +
"{{\"op\": \"replace\", \"path\": \"Text\", \"value\": \"testing-performance\"}}," +
"{{\"op\": \"add\", \"path\": \"Amount\", \"value\": 86632.172712}}," +
"{{\"op\": \"replace\", \"path\": \"Amount2\", \"value\": null}}," +
"{{\"op\": \"replace\", \"path\": \"SubTestModel\", \"value\": {{\"Id\": 91117, \"Data\": 78}}}}," +
"{{\"op\": \"test\", \"path\": \"Number\", \"value\": 86632}}," +
"{{\"op\": \"copy\", \"path\": \"Amount2\", \"from\": \"Amount\"}}," +
"{{\"op\": \"remove\", \"path\": \"Text\"}}" +
"]"
);


[Benchmark]
Original file line number Diff line number Diff line change
@@ -2,17 +2,17 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.7" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="Marvin.JsonPatch" Version="2.2.1" />
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="7.0.10" />
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="9.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

16 changes: 8 additions & 8 deletions SystemTextJsonPatch.Console/DeserializeTest.cs
Original file line number Diff line number Diff line change
@@ -7,14 +7,14 @@ public class DeserializeTest
{
public static string DeserializePatchDocJson = string.Format(
"[" +
"{{\"op\": \"replace\", \"path\": \"number\", \"value\": 86632}}," +
"{{\"op\": \"replace\", \"path\": \"text\", \"value\": \"testing-performance\"}}," +
"{{\"op\": \"add\", \"path\": \"amount\", \"value\": 86632.172712}}," +
"{{\"op\": \"replace\", \"path\": \"amount2\", \"value\": null}}," +
"{{\"op\": \"replace\", \"path\": \"subTestModel\", \"value\": {{\"id\": 91117, \"data\": 78}}}}," +
"{{\"op\": \"test\", \"path\": \"number\", \"value\": 86632}}," +
"{{\"op\": \"copy\", \"path\": \"amount2\", \"from\": \"amount\"}}," +
"{{\"op\": \"remove\", \"path\": \"text\"}}" +
"{{\"op\": \"replace\", \"path\": \"Number\", \"value\": 86632}}," +
"{{\"op\": \"replace\", \"path\": \"Text\", \"value\": \"testing-performance\"}}," +
"{{\"op\": \"add\", \"path\": \"Amount\", \"value\": 86632.172712}}," +
"{{\"op\": \"replace\", \"path\": \"Amount2\", \"value\": null}}," +
"{{\"op\": \"replace\", \"path\": \"SubTestModel\", \"value\": {{\"Id\": 91117, \"Data\": 78}}}}," +
"{{\"op\": \"test\", \"path\": \"Number\", \"value\": 86632}}," +
"{{\"op\": \"copy\", \"path\": \"Amount2\", \"from\": \"Amount\"}}," +
"{{\"op\": \"remove\", \"path\": \"Text\"}}" +
"]"
);

Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>
26 changes: 26 additions & 0 deletions SystemTextJsonPatch.Tests/ExceptionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using SystemTextJsonPatch.Exceptions;
using SystemTextJsonPatch.Tests.TestObjectModels;
using Xunit;

namespace SystemTextJsonPatch.Tests
{
public class ExceptionTests
{
[Fact]
public void OperationShouldBeAvailableInTheException()
{
var targetObject = new MyCustomDateOnly(2000, 10, 1);

var patchDocument = new JsonPatchDocument();
patchDocument.Replace("NewInt", 1);

// Act
var exc = Assert.Throws<JsonPatchException>(() => patchDocument.ApplyTo(targetObject));

Assert.Equal("The target location specified by path segment 'NewInt' was not found.", exc.Message);
Assert.NotNull(exc.FailedOperation);
Assert.Equal("replace", exc.FailedOperation.Op);
Assert.Equal("/NewInt", exc.FailedOperation.Path);
}
}
}
Loading