Replace JObject with object for Message.Payload#7376
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the NuGet plugin protocol Message payload surface to avoid exposing Newtonsoft.Json.Linq.JObject in the public API by changing Message.Payload/constructor payload from JObject to object, while keeping JSON payload handling working via helper/converter updates.
Changes:
- Change
NuGet.Protocol.Plugins.Message.Payloadand its constructor parameter type fromJObjecttoobject, and introduce a custom JSON converter for payload deserialization. - Update
MessageUtilities.DeserializePayload<TPayload>to handle bothJObjectpayloads and already-typed payload instances, and add a localized error string for invalid payload casts. - Update affected tests to compare payloads via
TestUtilities.Serialize(...)rather thanJObject.ToString(Formatting.None).
Reviewed changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| test/TestExtensions/TestablePlugin/TestablePlugin.cs | Switches initialization request handling to MessageUtilities.DeserializePayload<T>(). |
| test/NuGet.Core.Tests/NuGet.Protocol.Tests/Plugins/StandardInputReceiverTests.cs | Updates payload assertions to serialize object payloads for comparison. |
| test/NuGet.Core.Tests/NuGet.Protocol.Tests/Plugins/MessageUtilitiesTests.cs | Updates payload serialization assertion to use TestUtilities.Serialize. |
| test/NuGet.Core.Tests/NuGet.Protocol.Tests/Plugins/Messages/MessageTests.cs | Updates payload JSON assertions to serialize object payloads. |
| test/NuGet.Core.Tests/NuGet.Protocol.Tests/Plugins/MessageDispatcherTests.cs | Updates payload JSON assertions to serialize object payloads. |
| src/NuGet.Core/NuGet.Protocol/xlf/Strings.zh-Hant.xlf | Adds new localization entry for Plugin_InvalidPayloadCast. |
| src/NuGet.Core/NuGet.Protocol/xlf/Strings.zh-Hans.xlf | Adds new localization entry for Plugin_InvalidPayloadCast. |
| src/NuGet.Core/NuGet.Protocol/xlf/Strings.tr.xlf | Adds new localization entry for Plugin_InvalidPayloadCast. |
| src/NuGet.Core/NuGet.Protocol/xlf/Strings.ru.xlf | Adds new localization entry for Plugin_InvalidPayloadCast. |
| src/NuGet.Core/NuGet.Protocol/xlf/Strings.pt-BR.xlf | Adds new localization entry for Plugin_InvalidPayloadCast. |
| src/NuGet.Core/NuGet.Protocol/xlf/Strings.pl.xlf | Adds new localization entry for Plugin_InvalidPayloadCast. |
| src/NuGet.Core/NuGet.Protocol/xlf/Strings.ko.xlf | Adds new localization entry for Plugin_InvalidPayloadCast. |
| src/NuGet.Core/NuGet.Protocol/xlf/Strings.ja.xlf | Adds new localization entry for Plugin_InvalidPayloadCast. |
| src/NuGet.Core/NuGet.Protocol/xlf/Strings.it.xlf | Adds new localization entry for Plugin_InvalidPayloadCast. |
| src/NuGet.Core/NuGet.Protocol/xlf/Strings.fr.xlf | Adds new localization entry for Plugin_InvalidPayloadCast. |
| src/NuGet.Core/NuGet.Protocol/xlf/Strings.es.xlf | Adds new localization entry for Plugin_InvalidPayloadCast. |
| src/NuGet.Core/NuGet.Protocol/xlf/Strings.de.xlf | Adds new localization entry for Plugin_InvalidPayloadCast. |
| src/NuGet.Core/NuGet.Protocol/xlf/Strings.cs.xlf | Adds new localization entry for Plugin_InvalidPayloadCast. |
| src/NuGet.Core/NuGet.Protocol/Strings.resx | Adds Plugin_InvalidPayloadCast resource string. |
| src/NuGet.Core/NuGet.Protocol/Strings.Designer.cs | Adds generated accessor for Plugin_InvalidPayloadCast. |
| src/NuGet.Core/NuGet.Protocol/PublicAPI/net8.0/PublicAPI.Unshipped.txt | Adds updated Message API signatures as unshipped entries. |
| src/NuGet.Core/NuGet.Protocol/PublicAPI/net8.0/PublicAPI.Shipped.txt | Removes previously shipped Message constructor/payload entries (needs correction). |
| src/NuGet.Core/NuGet.Protocol/PublicAPI/net472/PublicAPI.Unshipped.txt | Adds updated Message API signatures as unshipped entries. |
| src/NuGet.Core/NuGet.Protocol/PublicAPI/net472/PublicAPI.Shipped.txt | Removes previously shipped Message constructor/payload entries (needs correction). |
| src/NuGet.Core/NuGet.Protocol/Plugins/ObjectPayloadConverter.cs | Adds a converter used by Message.Payload to deserialize JSON objects into JObject. |
| src/NuGet.Core/NuGet.Protocol/Plugins/MessageUtilities.cs | Updates payload deserialization to support object payloads and throw a localized cast error. |
| src/NuGet.Core/NuGet.Protocol/Plugins/Messages/Message.cs | Changes Payload and constructor payload parameter types from JObject to object and applies the converter attribute. |
Files not reviewed (1)
- src/NuGet.Core/NuGet.Protocol/Strings.Designer.cs: Language not supported
zivkan
reviewed
May 8, 2026
Nigusu-Allehu
commented
May 9, 2026
nkolev92
previously approved these changes
May 13, 2026
zivkan
previously approved these changes
May 13, 2026
Contributor
|
Added When you commit this breaking change:
You can refer to the .NET SDK breaking change guidelines |
zivkan
approved these changes
May 13, 2026
This was referenced May 14, 2026
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Fixes: NuGet/Home#14901
Description
Obsoletes
Message.Payload (JObject)and stores payloads as objectMessage.Payloadis marked[Obsolete]and now returns null. Payloads are stored internally as object in PayloadObject, serialized via[JsonProperty("Payload")]so the wire format is unchanged.MessageUtilities.Create<T>stores typed payloads directlyMessageUtilities.DeserializePayload<T>handles both JObject from JSON deserialization and typed object cases.This is a slice of #7326. It isolates the breaking API change from the larger STJ behavioral change: when the STJ MessageConverter lands
STJ integration path
When the STJ
MessageConverteris introduced, it will:Message.Payload(which is nowobject)PR Checklist