Skip to content

Ignore From when serializing a JsonPatchDocument for add, remove, rep… - #64457

Merged
Youssef1313 merged 8 commits into
dotnet:mainfrom
akshay-zz:fix/jsonpatch-from-null-v2
Jul 23, 2026
Merged

Youssef1313 merged 8 commits into
dotnet:mainfrom
akshay-zz:fix/jsonpatch-from-null-v2

Conversation

@akshay-zz

@akshay-zz akshay-zz commented Nov 20, 2025 •

Copy link
Copy Markdown
Contributor

Ignore "From" when serializing a JsonPatchDocument for "add", "remove", "replace" and "test" operations

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Summary of the changes (Less than 80 chars)

Description

Fixes #63862
Fixes #64123

#64031 Pr got closed mistakenly by @martincostello. Creating new one as we don't have the right to reopen it.

@akshay-zz
akshay-zz requested review from a team and tdykstra as code owners November 20, 2025 16:43
@github-actions github-actions Bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Nov 20, 2025
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 20, 2025
@martincostello martincostello added feature-json-patch area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Nov 20, 2025
@tdykstra
tdykstra requested review from wadepickett and removed request for tdykstra November 20, 2025 21:09
@wadepickett
wadepickett removed their request for review November 20, 2025 22:04
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Nov 28, 2025

@mikekistler mikekistler left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this fix! @Youssef1313 what do you think?

@Youssef1313 Youssef1313 self-assigned this May 26, 2026
~Microsoft.AspNetCore.JsonPatch.SystemTextJson.Operations.Operation<TModel>.Operation(string op, string path, string from, object value) -> void
~Microsoft.AspNetCore.JsonPatch.SystemTextJson.Operations.Operation<TModel>.Operation(string op, string path, string from) -> void
~Microsoft.AspNetCore.JsonPatch.SystemTextJson.Operations.OperationBase.from.get -> string
~Microsoft.AspNetCore.JsonPatch.SystemTextJson.Operations.OperationBase.from.set -> void

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a breaking change to the public API.

@halter73

Copy link
Copy Markdown
Member

@akshay-zz Sorry for the delay reviewing this PR. This is something we're interested in taking though. Are you still interested in working on this PR?

@akshay-zz

Copy link
Copy Markdown
Contributor Author

@halter73 yes, I'm interested in working in the PR. I will work this pr comment "Given the property is named in camelCase, it might be worth adding a test for the other one to ensure that ShouldSerializeFrom works correctly." Anything else you want me to take care?

@BrennanConroy

Copy link
Copy Markdown
Member

@akshay-zz There is also a breaking change, is that necessary for this PR?

@Youssef1313 Youssef1313 added the pr: pending author input For automation. Specifically separate from Needs: Author Feedback label Jun 22, 2026
@Youssef1313 Youssef1313 removed pr: pending author input For automation. Specifically separate from Needs: Author Feedback pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun labels Jul 22, 2026
{
// While ShouldSerializeValue appears unused. Be careful if you remove it.
// It decides whether or not the value property is serialized.
// It's used by STJ for deciding the JsonIgnore (WhenWritingDefault)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment doesn't make sense. It's used below at line 51. Unless STJ is doing something internally for properties named ShouldSerializeValue?

@Youssef1313 Youssef1313 Jul 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, the read at line 51 is actually always true.

If ShouldSerializeValue wasn't true, then we are always default, and we have already JsonIgnore for default.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted the condition at line 51. Actually if the condition was possible to be false, we would end up with syntactically invalid JSON altogether because STJ would have already written the property name and the colon, and then we would have skipped writing a value completely.

So I kept relying on the JsonIgnore with condition WhenWritingDefault.

this.from = from;
}

public bool ShouldSerializeFrom()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a comment here saying it's unused. Just kept around since it's public API. Maybe even mark it obsolete?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linked to #67966

@Youssef1313
Youssef1313 enabled auto-merge (squash) July 23, 2026 04:07
@Youssef1313
Youssef1313 merged commit 3e4dba0 into dotnet:main Jul 23, 2026
24 checks passed
@Youssef1313

Copy link
Copy Markdown
Member

/backport to release/11.0-preview7

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0-preview7 (link to workflow run)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc community-contribution Indicates that the PR has been added by a community member feature-json-patch

Projects

None yet

7 participants