Skip to content

System.Text.Json should support has buildin support read json number to string property #114054

Open
@John0King

Description

@John0King

background

currently the real big problem for people to switch from Newtonsoft.json to System.Text.json is that the S.T.J to too strict on deserialzing.

the bigest problem for me is the string <===> number , currently there is a JsonNumberHandling.AllowReadingFromString option for string ==> json, but not reverse, and WriteAsString is for serializing.

why you read a json number to a string property?

the user case for this is primary for 3rd party interface or compatibility.

  1. the remote 3rd party has a week languge, and use string|number for a json property
  2. or a system begin as number type , and then add string type , and for compatibility, the model for receive the json change from int => 'string'

using newtonsoft.json this is very simple , because newtonsoft.json allow string to accept any type in json, but for System.Text.Json, this must change type from int => JsonNode and involve json framework type

suggestion

JsonNumberHandling.AllowReadingFromString should also allow read number to string

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions