Skip to content

Serialize sbyte as JSON number in transport and execution writers#9846

Merged
glen-84 merged 1 commit into
mainfrom
gai/sbyte-transport-execution-json-writers
Jun 4, 2026
Merged

Serialize sbyte as JSON number in transport and execution writers#9846
glen-84 merged 1 commit into
mainfrom
gai/sbyte-transport-execution-json-writers

Conversation

@glen-84

@glen-84 glen-84 commented Jun 4, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to #9827. That PR added the missing sbyte case to StrawberryShake's JsonSerializationHelper, but as noted on #9825 that helper is not on the v16 HTTP request path, so Byte variables were still serialized as JSON strings.

The Byte scalar's runtime type is sbyte (ByteType : IntegerTypeBase<sbyte>), and the same byte-without-sbyte gap existed in two more JSON value writers:

  • Utf8JsonWriterHelper (HotChocolate.Transport.Abstractions) — the actual HTTP request path for StrawberryShake, GraphQLHttpClient, and Fusion subgraph requests. This is what fixes the reported issue.
  • JsonValueFormatter (HotChocolate.Execution.Abstractions) — reached when a boxed sbyte is formatted via extensions, Any, or raw dictionaries.

Both now emit sbyte as a JSON number instead of falling through to string serialization.

Test plan

  • Added OperationRequestTests.Should_WriteSByteVariableAsNumber — an sbyte variable serializes as 2, not "2", through OperationRequest.WriteTo.
  • Added JsonValueFormatterTests.WriteSByteAsNumberJsonValueFormatter.WriteValue emits sbyte as a number.
  • Both confirmed failing before the fix and passing after; Transport.Http.Tests (65) and Execution.Abstractions.Tests (105) pass on net8.0/net9.0/net10.0.

Closes #9825

Copilot AI review requested due to automatic review settings June 4, 2026 11:51

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.

Pull request overview

Fixes sbyte (Byte scalar runtime type in v16) being serialized as a JSON string in request/response JSON writers by adding explicit sbyte handling so it is emitted as a JSON number.

Changes:

  • Add sbyte handling to Utf8JsonWriterHelper.WriteFieldValue so OperationRequest.WriteTo (HTTP request path) writes sbyte variables as JSON numbers.
  • Add sbyte handling to JsonValueFormatter.WriteValue so boxed sbyte values (e.g., extensions/Any/raw dictionaries) format as JSON numbers.
  • Add targeted tests covering both writers’ sbyte serialization behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/HotChocolate/Core/src/Execution.Abstractions/Execution/JsonValueFormatter.cs Adds sbyte case to write boxed sbyte as a JSON number.
src/HotChocolate/AspNetCore/src/Transport.Abstractions/Serialization/Utf8JsonWriterHelper.cs Adds sbyte case to write transport-layer values as JSON numbers (fixes HTTP request serialization).
src/HotChocolate/Core/test/Execution.Abstractions.Tests/Execution/JsonValueFormatterTests.cs New unit test asserting JsonValueFormatter writes sbyte as 2 (number).
src/HotChocolate/AspNetCore/test/Transport.Http.Tests/OperationRequestTests.cs New unit test asserting OperationRequest.WriteTo serializes sbyte variables as numbers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@glen-84 glen-84 merged commit a43a58c into main Jun 4, 2026
145 checks passed
@glen-84 glen-84 deleted the gai/sbyte-transport-execution-json-writers branch June 4, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Byte scalar variable sent as JSON string, server rejects it on v16

2 participants