You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.NET number values such as positive and negative infinity cannot be written as valid JSON. #48926
area-System.Text.JsondocumentationDocumentation bug or enhancement, does not impact product or test codegood first issueIssue should be easy to implement, good for first-time contributorshelp wanted[up-for-grabs] Good issue for external contributors
In .NET 5 double.NaN is written to json as "NaN". Why not to write double.PositiveInfinity and double.NegativeInfinity as "PINF" and "NINF"? And the same for float.
It's not good that Infinity values throw an exception (.NET number values such as positive and negative infinity cannot be written as valid JSON.).
@TornhoofAllowNamedFloatingPointLiterals solved the problem, thanks a lot! The developers should add this info into the exception text.
Something like:
.NET number values such as positive and negative infinity cannot be written as valid JSON. Consider JsonNumberHandling.AllowNamedFloatingPointLiterals to make it work.
The developers should add this info into the exception text. Something like:
.NET number values such as positive and negative infinity cannot be written as valid JSON. Consider JsonNumberHandling.AllowNamedFloatingPointLiterals to make it work.
I think this is a clarification that might make sense to incorporate in the exception message (with strong wording indicating that this will generate json incompatible with many applications). @layomia thoughts? @GrabYourPitchforks might be opinionated on this as well.
Any exception text that helps developers better accomplish their task is goodness. :)
The trick is that the exception text shouldn't say "do xyz" unless xyz is undoubtedly the right thing to do. If there's any nuance involved (e.g., "you can do this, but you need to be aware that it will create non-interoperable JSON") then it's often best to provide a link to a page that better explains all the scenarios.
@deeprobin sure. Note that this task involves updating the JsonNumberHandling.WriteAsString/AllowNamedFloating point API documentation as pointed out in #48926 (comment), and also manually updating the corresponding entries in the dotnet/dotnet-api-docs repo (via a separate PR in that repo). Then, the augmented exception message should link to the JsonNumberHandling documentation on the docs website.
area-System.Text.JsondocumentationDocumentation bug or enhancement, does not impact product or test codegood first issueIssue should be easy to implement, good for first-time contributorshelp wanted[up-for-grabs] Good issue for external contributors
Activity
Tornhoof commentedon Mar 1, 2021
JSON does not support NaN or Inf.
See https://tools.ietf.org/html/rfc8259#section-6
That said, did you enable the appropriate flag https://docs.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializeroptions.numberhandling?view=net-5.0?
With that you should be able to handle these values.
rodion-m commentedon Mar 1, 2021
@Tornhoof
AllowNamedFloatingPointLiteralssolved the problem, thanks a lot! The developers should add this info into the exception text.Something like:
eiriktsarpalis commentedon Mar 2, 2021
I think this is a clarification that might make sense to incorporate in the exception message (with strong wording indicating that this will generate json incompatible with many applications). @layomia thoughts? @GrabYourPitchforks might be opinionated on this as well.
GrabYourPitchforks commentedon Mar 2, 2021
Any exception text that helps developers better accomplish their task is goodness. :)
The trick is that the exception text shouldn't say "do xyz" unless xyz is undoubtedly the right thing to do. If there's any nuance involved (e.g., "you can do this, but you need to be aware that it will create non-interoperable JSON") then it's often best to provide a link to a page that better explains all the scenarios.
deeprobin commentedon Nov 18, 2021
If you want you can assign me :)
layomia commentedon Nov 18, 2021
@deeprobin sure. Note that this task involves updating the
JsonNumberHandling.WriteAsString/AllowNamedFloatingpoint API documentation as pointed out in #48926 (comment), and also manually updating the corresponding entries in the dotnet/dotnet-api-docs repo (via a separate PR in that repo). Then, the augmented exception message should link to theJsonNumberHandlingdocumentation on the docs website.deeprobin commentedon Feb 13, 2022
I think this can be closed (PRs merged)
/cc @layomia
rodion-m commentedon Feb 13, 2022
Thanks a lot!