Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Patch 2.0.3 #317

Merged
merged 3 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions JsonPatch.Tests/PatchExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,23 @@ public void CreatePatch_RemoveArrayItem()
Assert.AreEqual(model.InnerObjects[1].Id, final.InnerObjects[0].Id);
}

[Test]
public void ApplyPatch_Respect_SerializationOptions()
{
var model = new TestModel
{
Numbers = new int[0],
};

var patchStr = "[{\"op\":\"add\",\"path\":\"/numbers/-\",\"value\":5}]";
var patch = JsonSerializer.Deserialize<JsonPatch>(patchStr)!;

var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
var final = patch.Apply(model, options);

Assert.AreEqual(5, final?.Numbers?[0]);
}

private static void OutputPatch(JsonPatch patch)
{
Console.WriteLine(JsonSerializer.Serialize(patch, new JsonSerializerOptions { WriteIndented = true }));
Expand Down
4 changes: 2 additions & 2 deletions JsonPatch/JsonPatch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<RootNamespace>Json.Patch</RootNamespace>
<Version>2.0.2</Version>
<Version>2.0.3</Version>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.2.0</FileVersion>
<FileVersion>2.0.3.0</FileVersion>
<PackageId>JsonPatch.Net</PackageId>
<Authors>Greg Dennis</Authors>
<Company>Greg Dennis</Company>
Expand Down
2 changes: 1 addition & 1 deletion JsonPatch/PatchExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static class PatchExtensions
/// <exception cref="InvalidOperationException">Thrown when the patch cannot be applied.</exception>
public static TTarget? Apply<TOriginal, TTarget>(this JsonPatch patch, TOriginal obj, JsonSerializerOptions? options = null)
{
var node = JsonSerializer.SerializeToNode(obj);
var node = JsonSerializer.SerializeToNode(obj, options);
var patchResult = patch.Apply(node);
if (!patchResult.IsSuccess)
throw new InvalidOperationException($"{patchResult.Error} Operation: {patchResult.Operation}");
Expand Down
6 changes: 5 additions & 1 deletion json-everything.net/wwwroot/md/release-notes/json-patch.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# 2.0.1 (no PR)
# [2.0.3](https://github.com/gregsdennis/json-everything/pull/317)

[#315](https://github.com/gregsdennis/json-everything/pull/315) - [@z4kn4fein](https://github.com/z4kn4fein) noticed that the serializer options weren't actually being passed into the `.Apply()` call.

# 2.0.2 (no PR)

[#291](https://github.com/gregsdennis/json-everything/pull/291) - Improved patch generation for arrays.

Expand Down