Skip to content

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

@nicoguedes

Description

@nicoguedes

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions