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
Json: allow customizing (some) serialization options when creating json, so that it's more readable #28815
Currently we use default serialization options, but it would be nice to allow some customization in how the json looks (e.g. casing of property names. Similar thing was asked on npg: npgsql/efcore.pg#1107
Reacted by Viktor Svub, mojtaba kaviani, Marcel Bradea, ouvré thomas, Markus Schaber, alienwareone, Tanvir Ahmad Arjel, ZixZux and wizofaus
@maumar What are the default serialization options?
I was expecting that enum values are serialized to int values by default, but they are serialized as string values.
(Which is desired by myself but I'm curious why?)
enum Test { One, Two, Three }
[Fact]
public async Task Json_serialize_enum_as_int_value()
{
var test = Test.Two;
var json = System.Text.Json.JsonSerializer.Serialize(test);
json.Should().Be("1");
}
@alienwareone enum converted to string is pretty much only "customization" we do by default. The idea was that the JSON should be somewhat human-readable, so we decided to store it as strings.
Activity
alienwareone commentedon Sep 27, 2022
@maumar What are the default serialization options?
I was expecting that enum values are serialized to int values by default, but they are serialized as string values.
(Which is desired by myself but I'm curious why?)
maumar commentedon Oct 19, 2022
@alienwareone enum converted to string is pretty much only "customization" we do by default. The idea was that the JSON should be somewhat human-readable, so we decided to store it as strings.
maumar commentedon Oct 19, 2022
dupe of #28043