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
If I serialize an integral double value (e.g 1.0), it becomes a string.
EDIT: From debugging, it looks like NumericRegex in JsonEventEmitter.cs is wrong. It does not match against single-digit numbers. For example, it matches 10, but not 1. Perhaps change it to something like ^-?\d+(\.\d+)?$.
EDIT2: I expect this will be fixed by this pull request. I hope it can be made official soon ... 😁
Here's my test code ...
[Fact]publicvoidTestNumberDeserialization(){vardeserializer=new DeserializerBuilder().WithAttemptingUnquotedStringTypeDeserialization().Build();varyaml=string.Join('\n',"DoubleValue: 1.03","OtherDoubleValue: 1.0","StringValue: \"abc\"","IntValue: 234","BooleanValue: true");varyamlObject= deserializer.Deserialize(yaml);varserializer=new SerializerBuilder().JsonCompatible().Build();varjson= serializer.Serialize(yamlObject);// At ths point, json = {"DoubleValue": 1.03, "OtherDoubleValue": "1", "StringValue": "abc", "IntValue": 234, "BooleanValue": true}// Why has OtherDoubleValue got quotes around it?// Next line fails with error about converting String to Double.vartestObject= JsonSerializer.Deserialize<TestType>(json);
testObject.DoubleValue.Should().Be(1.03);
testObject.OtherDoubleValue.Should().Be(1.0);
testObject.StringValue.Should().Be("abc");
testObject.IntValue.Should().Be(234);
testObject.BooleanValue.Should().BeTrue();}
The text was updated successfully, but these errors were encountered:
If I serialize an integral double value (e.g
1.0
), it becomes a string.EDIT: From debugging, it looks like
NumericRegex
inJsonEventEmitter.cs
is wrong. It does not match against single-digit numbers. For example, it matches10
, but not1
. Perhaps change it to something like^-?\d+(\.\d+)?$
.EDIT2: I expect this will be fixed by this pull request. I hope it can be made official soon ... 😁
Here's my test code ...
The text was updated successfully, but these errors were encountered: