-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Nullable with JsonSerializer #725
Comments
This is not related to nullable but instead using strings to represent numbers which is not currently supported by the serializer, reader\writer or JsonDocument. Currently the best workaround (if you cannot control the incoming JSON to not use strings to represent numbers) is to create a custom converter for the number types. One example of a converter for Int32 is here. |
The workaround works but it does not look nice to have converters for all system number types (even I made a base generic class for that). Will such "string - number" conversion be included at the System.Text.Json by default? In my situation I cannot control what JSON we receive, so our system need to "eat" all "look correct" values. |
We are currently prioritizing features for 5.0 and support for string numeric types has been requested previously including the common case where numeric types are used as the Key for a Dictionary (assuming the JSON format for Dictionaries uses I'll mark this 5.0 for now until to triage it and link to related issues. |
As @steveharter mentioned, this issue is about deserializing JSON strings into numbers which isn't supported by the serializer. We have an issue tracking this, so I'll close this as a duplicate: https://github.com/dotnet/corefx/issues/39473. |
I am migrating to .NET Core 3.1 and have a class with null-able values (decimal, DateTime) and want deserialize JSON to it. I received JSON from a client with property values as strings. Here is the sample code:
This code throws an error:
'The JSON value could not be converted to System.Nullable`1[System.Decimal].
I have tried to use a workarounf at:
https://github.com/dotnet/corefx/issues/41070#issuecomment-555395612
but it does not help. Can something be some with that? Any workaround? Newtonsoft can handle that without problems.
The text was updated successfully, but these errors were encountered: