This repository was archived by the owner on Nov 15, 2018. It is now read-only.
This repository was archived by the owner on Nov 15, 2018. It is now read-only.
JsonPatchDocument.Replace() yields invalid path when [JsonProperty] is used (1.1.0) #50
Closed
Description
Title
In 1.1.0
, JsonPatchDocument<T>.Replace()
creates Operation<T>
with invalid path
, when [JsonProperty]
from Newtonsoft.Json
is used.
Functional impact
This is regression from "Microsoft.AspNetCore.JsonPatch": "1.0.0"
and breaks existing behavior.
Minimal repro steps
global.json
:
"sdk": {
"version": "1.0.0-preview2-1-003177"
}
project.json
:
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.AspNetCore.JsonPatch": "1.1.0",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
},
"Newtonsoft.Json": "9.0.1"
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
Program.cs
:
using System.Diagnostics;
using System.Linq;
using Microsoft.AspNetCore.JsonPatch;
using Newtonsoft.Json;
namespace JsonPatchReplaceIssue
{
public class Model
{
[JsonProperty]
public string[] ArrayOfStringsOrNull { get; set; }
}
public class Program
{
public static void Main(string[] args)
{
var patch = new JsonPatchDocument<Model>()
.Replace(m => m.ArrayOfStringsOrNull, new[]
{
"yo"
});
var operation = patch.Operations.Single();
Debug.Assert(operation.path == $"/{nameof(Model.ArrayOfStringsOrNull).ToLowerInvariant()}",
$"No it ain't! It is '{operation.path}'");
}
}
}
Expected result
The Operation<T>.path
should be derived from the property in the expression. Expected path
to be "/arrayofstringsornull"
in this case.
Actual result
Actual path
is "/"
, which is incorrect.
Further technical details
Regression from "Microsoft.AspNetCore.JsonPatch": "1.0.0"
with .NET Core 1.0
.
I have tested:
- Change the
JsonPatch
dependency inproject.json
to1.0.0
and it works as expected. - Remove
[JsonProperty]
and it works as expected.
Question
Am I doing it wrong? I'm assuming that Newtonsoft.Json
's attributes are supported.