Skip to content

System.Text.Json changes the data datatype from double to int on serialization #35195

@minato7

Description

@minato7

This is an issue found while upgrading to System.Text.Json in Asp.NET Core 3.1. We have two webservices which interact based on Json contract.

When webservice1 based on ASP.NET Core, serializes using System.Text.Json a data with datatype double with value 312.0 is passed to Python webservice, we expect serialization to have double value, but this is not the case with System.Text.Json.

This double value is serialized as int value which is causing our webservice2 to treat it as int value 312 and causing variation in floating point results.

This was working perfectly fine with Newtonsoft.Json, as it treats double value 312.0 on serialization to be 312.0

I have uploaded the repo in this link:
https://github.com/minato7/IssueSystemTextJsonDouble

My assumption is if a contract has double datatype, it should be treated as double upon serialization and if it converts to int datatype this is an unexpected behavior, there should be an option provided to treat this double like FloatParseHandling in Newtonsoft.Json to achieve this behavior in System.Text.Json.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions