Skip to content

Document byte array deserialization differences between Newtonsoft.Json and System.Text.Json (Fixes #41394) - #56654

Open
Manish-1kumar wants to merge 2 commits into
dotnet:mainfrom
Manish-1kumar:users/manish/issue-41394-byte-array-serialization
Open

Manish-1kumar wants to merge 2 commits into
dotnet:mainfrom
Manish-1kumar:users/manish/issue-41394-byte-array-serialization

Conversation

@Manish-1kumar

@Manish-1kumar Manish-1kumar commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

Resolves #41394.

In \docs/standard/serialization/system-text-json/migrate-from-newtonsoft.md, documents behavioral differences between \Newtonsoft.Json\ and \System.Text.Json\ when deserializing \�yte[].\

Changes Included

  • Added an entry to the Table of differences linking to the new section.
  • Added a dedicated section Byte arrays under Scenarios using JsonSerializer.\
  • Documented that while both libraries serialize \�yte[]\ as Base64 strings by default, \Newtonsoft.Json\ accepts JSON number arrays (such as [1, 2, 3]) during deserialization, whereas \System.Text.Json\ strictly expects Base64 and throws a \JsonException\ on JSON arrays.\
  • Provided sample code for a custom \JsonConverter<byte[]>\ that handles both Base64 strings and JSON number arrays.\
  • Validated with \markdownlint-cli2\ (0 issues).

Internal previews

File Preview link
docs/standard/serialization/system-text-json/migrate-from-newtonsoft.md Learn preview

Build report

@dotnetrepoman dotnetrepoman Bot added this to the November 2026 milestone Nov 1, 2026
@dotnet-policy-service dotnet-policy-service Bot added dotnet-fundamentals/svc community-contribution Indicates PR is created by someone from the .NET community. labels Nov 1, 2026
@BillWagner
BillWagner requested a balanced review from Copilot November 24, 2026 14:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The converter changes byte-array serialization from Base64 to numeric arrays, risking consumer compatibility; it should preserve Base64 output while broadening deserialization.

1 open issue
What changed in this PR

Extends the System.Text.Json migration guide to address #41394 by explaining how byte-array deserialization differs from Newtonsoft.Json.

Changes:

  • Adds a differences-table entry linked to a new Byte arrays section.
  • Documents default Base64 serialization and differing support for numeric-array input.
  • Provides a custom converter example that accepts both input formats.
File Description
docs/​standard/​serialization/​system-text-json/​migrate-from-newtonsoft.md Adds byte-array migration guidance, a converter example, and an updated content date.

Review effort: Balanced

@Manish-1kumar
Manish-1kumar force-pushed the users/manish/issue-41394-byte-array-serialization branch from cf40d4e to 08e83cc Compare November 30, 2026 17:53

@BillWagner BillWagner left a comment

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 is a good start @Manish-1kumar

I have one major comment to address.


To deserialize a JSON number array into a `byte[]` with `System.Text.Json`, use a custom converter:

```csharp

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 sample is significant enough, it should be in a snippet and under our CI system. I'd also like the sample to run some output to verify correctness.

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

Labels

community-contribution Indicates PR is created by someone from the .NET community. dotnet-fundamentals/svc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[UUF] Missing info about serializing byte[]

3 participants