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

JSON Delta Formatter remove operation does not keep the previous value #59

Open
nicoguedes opened this issue Oct 14, 2021 · 1 comment

Comments

@nicoguedes
Copy link

I've got the following inputs and I'm using the JSON Delta formatter:

            {
                person = new
                {
                    name = "John Doe",
                    dob = DateTime.Now
                },
                addresses = new List<string>() { "address 1", "address 2" }
            };

            dynamic newObject = new
            {
                person = new
                {
                    name = "Patrick",
                },
                addresses = new List<string>() { "address 1", "address 3" }
            };

The response is:

{"path":"/person/dob","op":"remove","from":null,"value":null}

If I were using the default formatter, I would have for the dob field something like that:

 "dob": [
      "2021-10-14T15:41:57.7683884-03:00",
      0,
      0
    ]

I would expect to be able to have the previous value in the JSON Patch response too.

I'm creating my own formatter inheriting from the JsonDeltaFormatter class and overriding this method:

protected override void Format(DeltaType type, JsonFormatContext context, JToken delta, JToken leftValue, string key, string leftKey, MoveDestination movedFrom)

More specifically this line, that only takes the context into account, without the delta:

However, if this is not working as designed I'd rather open a PR.

@MrXander
Copy link

I tried to workaround it here:
https://github.com/MrXander/json-diff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants