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
Describe the bug
When serialize data to JSON.
Some data are serialized as unexpected representation.
1. Serialized JSON data of floating number that contains Exponential Notation is serialized as string.
This behavior is changed by #893.
And it's required to enable JsonNumberHandling.AllowReadingFromString options to deserialize these values as float/double.
Older version of YamlDotNet serialize these data as number.
2. Serialized JSON data of Nan/PositiveInfinite/NegativeInfinite can't be deserialized with System.Text.Json
YamlDotNet serialize these values as string(.nan/.inf/-.inf).
But it's not compatible with JsonNumberHandling.AllowNamedFloatingPointLiterals options.
To Reproduce
UnitTest Code
publicclassYamlJsonRoundTripTests{privatestaticISerializerYamlJsonSerializer=newSerializerBuilder().JsonCompatible().Build();privatestaticJsonSerializerOptionsCustomSerializerOptions=newJsonSerializerOptions{NumberHandling=JsonNumberHandling.AllowReadingFromString|JsonNumberHandling.AllowNamedFloatingPointLiterals};[Theory][InlineData(1.234d,false)][InlineData(double.MinValue,false)][InlineData(double.MaxValue,false)]// Following data should be serialized to quoted JSON value.[InlineData(double.PositiveInfinity,true)][InlineData(double.NegativeInfinity,true)][InlineData(double.NaN,true)]publicvoidYamlJsonRoundTripTest_SystemTextJson(objectvalue,boolexpectQuoted){// Arrange/Actstringjson=YamlJsonSerializer.Serialize(value);varresult=System.Text.Json.JsonSerializer.Deserialize(json,value.GetType(),CustomSerializerOptions);// Assertresult.Should().BeOfType(value.GetType());result.Should().Be(value);if(expectQuoted){json.Should().StartWith("\"").And.EndWith("\"");}else{json.Should().NotStartWith("\"").And.NotEndWith("\"");}}}
The text was updated successfully, but these errors were encountered:
Having the same problem currently while updating to 16.x.
We have normal floating points (all digits) but there is similar problem with floats like 3.0, 0.0 etc.
Essentially single digit at the front and ending on .0.
After looking at the code for a while I think the problem is that during the JsonEventEmitter code the "G" string formatting for doubles will remove the .0 and the numericRegex ^-?\d+\.?\d+$" does not match single digit numbers.
Issue being here that the regex made only the "." optional, not the \d afterwards.
Should be fixable with this ^-?\d+(\.\d+)?$
Describe the bug
When serialize data to JSON.
Some data are serialized as unexpected representation.
1. Serialized JSON data of
floating number
that containsExponential Notation
is serialized asstring
.This behavior is changed by #893.
And it's required to enable
JsonNumberHandling.AllowReadingFromString
options to deserialize these values asfloat/double
.Older version of YamlDotNet serialize these data as
number
.2. Serialized JSON data of
Nan
/PositiveInfinite
/NegativeInfinite
can't be deserialized with System.Text.JsonYamlDotNet serialize these values as string(
.nan
/.inf
/-.inf
).But it's not compatible with JsonNumberHandling.AllowNamedFloatingPointLiterals options.
To Reproduce
UnitTest Code
The text was updated successfully, but these errors were encountered: