-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Open
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Text.Json
Milestone
Description
Serializing the same dictionary but with entries added in different order in STJ can result in different results every time you run your app. We should offer converter/option which can make this behavior stable.
Repro:
using System.Text.Json;
Test repro = new Test();
if (Environment.TickCount % 2 == 0)
{
repro.Dict.Add("left", "foo");
repro.Dict.Add("right", "bar");
}
else
{
repro.Dict.Add("right", "bar");
repro.Dict.Add("left", "foo");
}
Console.WriteLine(JsonSerializer.Serialize(repro));
public class Test
{
public Dictionary<string, string> Dict { get; } = new();
}Output (randomly one of the following two):
{"Dict":{"left":"foo","right":"bar"}}
or
{"Dict":{"right":"bar","left":"foo"}}
Expected output:
{"Dict":{"left":"foo","right":"bar"}}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Text.Json