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

[Preview5] JsonSerializer cannot convert boolean to string #29584

Closed
ianjirka opened this issue May 17, 2019 · 4 comments
Closed

[Preview5] JsonSerializer cannot convert boolean to string #29584

ianjirka opened this issue May 17, 2019 · 4 comments

Comments

@ianjirka
Copy link

It converts to a string using newtonsoft. Workaround is easy, filing a bug as FYI.

System.Text.Json.JsonReaderException: The JSON value from [RecaptchaVerificationResponse].success could not be converted to System.String.
   at System.Text.Json.ThrowHelper.ThrowJsonReaderException_DeserializeUnableToConvertValue(Type propertyType, Utf8JsonReader& reader, ReadStack& state)
...
public class RecaptchaVerificationResponse
    {
        public string success {get;set;}
        public DateTime challenge_ts {get;set;}
        public string hostname {get;set;}
        [JsonProperty("error-codes")]
        public string[] error_codes {get;set;}
    }
{"success": true,"challenge_ts": "2019-05-17T02:23:27Z","hostname": "testkey.google.com"}
@ahsonkhan
Copy link
Member

This is a known limitation of the JsonSerializer, by design. We generally avoid loose types/inferring what types could work between JSON and .NET types and only do "strict" matching.

We are working to provide an extension capability that will let callers write their own converters which is more flexible.

cc @steveharter, @JeremyKuhne

@ahsonkhan
Copy link
Member

ahsonkhan commented May 17, 2019

Also cc @JamesNK, @rynowak

@ianjirka
Copy link
Author

Makes sense, thank you @ahsonkhan

@ahsonkhan
Copy link
Member

The extension/converter feature is tracked by https://github.com/dotnet/corefx/issues/36639.

Closing as by-design.

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 3.0 milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants