Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json: allow customizing (some) serialization options when creating json, so that it's more readable #28815

Closed
maumar opened this issue Aug 21, 2022 · 3 comments

Comments

@maumar
Copy link
Contributor

maumar commented Aug 21, 2022

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

@alienwareone
Copy link

@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");
}

@maumar
Copy link
Contributor Author

maumar commented 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
Copy link
Contributor Author

maumar commented Oct 19, 2022

dupe of #28043

@maumar maumar removed this from the Backlog milestone Oct 19, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants