-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
area-System.Text.Jsonbugin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
Description
When serializing object containing property marked with [JsonExtensionData] attribute, serializer produces invalid JSON like this one: {"Id":1,{"nested":true}}
Reproduction Steps
Run the following code
var mix = new Mix
{
Id = 1,
Extra = new() { ["nested"] = true, }
};
var text = System.Text.Json.JsonSerializer.Serialize(mix);
Console.WriteLine(text);
// output {"Id":1,{"nested":true}}
public class Mix
{
public int Id { get; set; }
[System.Text.Json.Serialization.JsonExtensionData]
public System.Text.Json.Nodes.JsonObject? Extra { get; set; }
}Expected behavior
Correct JSON like {"Id":1,"nested":true} or at least valid JSON as if there was not [JsonExtensionData] attribute ({"Id":1,"Extra":{"nested":true}} ).
Actual behavior
Invalid JSON {"Id":1,{"nested":true}}
Regression?
Reproducible at least on .Net 6 to .Net 8
Known Workarounds
No response
Configuration
.Net 8
Windows 11
x64
Other information
No response
Swimburger, AdamDavidHill and mus65Copilot
Metadata
Metadata
Assignees
Labels
area-System.Text.Jsonbugin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged