Skip to content

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

Closed as duplicate

Description

@maumar

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

Activity

  1. added this to the Backlog milestone on Aug 22, 2022
  2. alienwareone commented on Sep 27, 2022

    @alienwareone

    @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");
    }
    
  3. maumar commented on Oct 19, 2022

    @maumar
    ContributorAuthor

    @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.

  4. maumar commented on Oct 19, 2022

    @maumar
    ContributorAuthor

    dupe of #28043

  5. removed this from the Backlog milestone on Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions