You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
System.Text.Json source generator emits "" for null byte[] properties #129833
The System.Text.Json source generator serializes a null byte[] property as an empty string ("") instead of null, diverging from the reflection-based serializer. The reflection path (ByteArrayConverter) writes null for a null byte[]; the generated fast path writes "", breaking round-tripping and backward compatibility.
Reproduction Steps
using System.Text.Json;
using System.Text.Json.Serialization;
var poco = new Poco(); // Data is null
Console.WriteLine(JsonSerializer.Serialize(poco)); // reflection
Console.WriteLine(JsonSerializer.Serialize(poco, Ctx.Default.Poco)); // source-gen
class Poco { public byte[]? Data { get; set; } }
[JsonSerializable(typeof(Poco))]
partial class Ctx : JsonSerializerContext { }
Expected behavior
Both serializers produce the same output: {"Data":null}
Actual behavior
The source generator produces: {"Data":""}
Regression?
No
Known Workarounds
Use a custom converter.
Configuration
Affects all current versions where the STJ source generator emits the Base64 fast path (reproduces on .NET 8/9/10/current main).
Activity
dotnet-policy-service commentedon Jun 25, 2026
Tagging subscribers to this area: @dotnet/area-system-text-json
See info in area-owners.md if you want to be subscribed.
lezzi commentedon Jun 25, 2026
I drafted #129834, but open to feedback about best possible approach here before I officially open it.
[JSON] Fix source generator serializing null byte[] as empty string (#…
[JSON] Fix source generator serializing null byte[] as empty string (#…