Skip to content

Replace JObject with object for Message.Payload#7376

Merged
Nigusu-Allehu merged 11 commits into
devfrom
dev-nyenework-plugins-payload-object
May 14, 2026
Merged

Replace JObject with object for Message.Payload#7376
Nigusu-Allehu merged 11 commits into
devfrom
dev-nyenework-plugins-payload-object

Conversation

@Nigusu-Allehu
Copy link
Copy Markdown
Member

@Nigusu-Allehu Nigusu-Allehu commented May 7, 2026

Bug

Fixes: NuGet/Home#14901

Description

Obsoletes Message.Payload (JObject) and stores payloads as object

Message.Payload is 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 directly
MessageUtilities.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 MessageConverter is introduced, it will:

  1. Deserialize payloads directly into typed objects using method-to-type dictionaries
  2. Store the typed object in Message.Payload (which is now object)

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@Nigusu-Allehu Nigusu-Allehu self-assigned this May 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.Payload and its constructor parameter type from JObject to object, and introduce a custom JSON converter for payload deserialization.
  • Update MessageUtilities.DeserializePayload<TPayload> to handle both JObject payloads 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 than JObject.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

Comment thread src/NuGet.Core/NuGet.Protocol/PublicAPI/net8.0/PublicAPI.Unshipped.txt Outdated
Comment thread src/NuGet.Core/NuGet.Protocol/PublicAPI/net472/PublicAPI.Unshipped.txt Outdated
Comment thread src/NuGet.Core/NuGet.Protocol/Plugins/Messages/Message.cs
Comment thread src/NuGet.Core/NuGet.Protocol/Plugins/ObjectPayloadConverter.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 26 out of 27 changed files in this pull request and generated 5 comments.

Files not reviewed (1)
  • src/NuGet.Core/NuGet.Protocol/Strings.Designer.cs: Language not supported

Comment thread src/NuGet.Core/NuGet.Protocol/Plugins/ObjectPayloadConverter.cs Outdated
Comment thread src/NuGet.Core/NuGet.Protocol/Plugins/ObjectPayloadConverter.cs Outdated
Comment thread src/NuGet.Core/NuGet.Protocol/Plugins/Messages/Message.cs
Comment thread src/NuGet.Core/NuGet.Protocol/PublicAPI/net472/PublicAPI.Unshipped.txt Outdated
Comment thread test/NuGet.Core.Tests/NuGet.Protocol.Tests/Plugins/Messages/MessageTests.cs Outdated
@Nigusu-Allehu Nigusu-Allehu marked this pull request as draft May 13, 2026 02:00
@Nigusu-Allehu Nigusu-Allehu marked this pull request as ready for review May 13, 2026 17:57
nkolev92
nkolev92 previously approved these changes May 13, 2026
Comment thread src/NuGet.Core/NuGet.Protocol/Plugins/MessageUtilities.cs
@Nigusu-Allehu Nigusu-Allehu requested review from jeffkl and zivkan May 13, 2026 20:08
zivkan
zivkan previously approved these changes May 13, 2026
Comment thread src/NuGet.Core/NuGet.Protocol/Plugins/MessageUtilities.cs Outdated
Comment thread src/NuGet.Core/NuGet.Protocol/Plugins/MessageUtilities.cs
@Nigusu-Allehu Nigusu-Allehu added the Breaking-change Label for .NET SDK breaking changes. label May 13, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Added needs-breaking-change-doc-created label because this PR has the breaking-change label.

When you commit this breaking change:

  1. Create and link to this issue a matching issue in the dotnet/docs repo using the breaking change documentation template, then remove this needs-breaking-change-doc-created label.
  2. Ask a committer to mail the .NET SDK Breaking Change Notification email list.

You can refer to the .NET SDK breaking change guidelines

@Nigusu-Allehu Nigusu-Allehu dismissed stale reviews from zivkan and nkolev92 via 9647664 May 13, 2026 21:28
@Nigusu-Allehu Nigusu-Allehu requested a review from zivkan May 13, 2026 21:32
@Nigusu-Allehu Nigusu-Allehu enabled auto-merge (squash) May 13, 2026 21:44
@Nigusu-Allehu Nigusu-Allehu merged commit c07a9b9 into dev May 14, 2026
17 of 18 checks passed
@Nigusu-Allehu Nigusu-Allehu deleted the dev-nyenework-plugins-payload-object branch May 14, 2026 00:34
@Nigusu-Allehu Nigusu-Allehu mentioned this pull request May 21, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking-change Label for .NET SDK breaking changes. needs-breaking-change-doc-created

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plugin Message.Payload is tied to Newtonsoft.Json (JObject), blocking STJ migration

5 participants