Skip to content

[System.Text.Json] Serializer loses precision on ulong #52393

@queequac

Description

@queequac

Description

Serializing an ulong to JSON within asp.net core loses precision. Stumbled over this while upgrading an older project from traditional ASPnet to .net core 8.

Reproduction Steps

Using .net 8 and System.Text.Json 8.0.0.

        public class Test
        {
            public ulong Key { get; set; }
        }

Exposing data via minimal API

            app.MapGet("/api/test", async (HttpContext context) =>
            {
                return new Test() { Key = 2121241830635120343 };
            });

The result in the browser is the following:

{
    "Key": 2121241830635120400
}

Expected behavior

{
    "Key": 2121241830635120343 
}

Actual behavior

{
    "Key": 2121241830635120400
}

Regression?

No response

Known Workarounds

For the moment I have written a custom JsonConverter which calls ToString for the ulong myself.

Configuration

.net 8, running x64 (emulated on win dev kit arm64) on Windows 11.

System.Text.Json 8.0.0

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.Needs: ReproIndicates that the team needs a repro project to continue the investigation on this issuearea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions