Serialize sbyte as JSON number in transport and execution writers#9846
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
sbytehandling toUtf8JsonWriterHelper.WriteFieldValuesoOperationRequest.WriteTo(HTTP request path) writessbytevariables as JSON numbers. - Add
sbytehandling toJsonValueFormatter.WriteValueso boxedsbytevalues (e.g.,extensions/Any/raw dictionaries) format as JSON numbers. - Add targeted tests covering both writers’
sbyteserialization 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.
This was referenced Jun 5, 2026
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.
Summary
Follow-up to #9827. That PR added the missing
sbytecase to StrawberryShake'sJsonSerializationHelper, but as noted on #9825 that helper is not on the v16 HTTP request path, soBytevariables were still serialized as JSON strings.The
Bytescalar's runtime type issbyte(ByteType : IntegerTypeBase<sbyte>), and the samebyte-without-sbytegap 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 boxedsbyteis formatted viaextensions,Any, or raw dictionaries.Both now emit
sbyteas a JSON number instead of falling through to string serialization.Test plan
OperationRequestTests.Should_WriteSByteVariableAsNumber— ansbytevariable serializes as2, not"2", throughOperationRequest.WriteTo.JsonValueFormatterTests.WriteSByteAsNumber—JsonValueFormatter.WriteValueemitssbyteas a number.Transport.Http.Tests(65) andExecution.Abstractions.Tests(105) pass on net8.0/net9.0/net10.0.Closes #9825