@@ -911,6 +911,55 @@ public void NullsRoundTrip()
911911 result . MyString . Should ( ) . BeNull ( ) ;
912912 }
913913
914+ [ Fact ]
915+ public void SerializationOfNumericsAsJsonRountTrip ( )
916+ {
917+ var serializer = new SerializerBuilder ( ) . JsonCompatible ( ) . Build ( ) ;
918+ var deserializer = new DeserializerBuilder ( ) . Build ( ) ;
919+
920+ var data = new
921+ {
922+ FloatValue1 = float . MinValue ,
923+ FloatValue2 = float . MaxValue ,
924+ FloatValue3 = float . NaN ,
925+ FloatValue4 = float . PositiveInfinity ,
926+ FloatValue5 = float . NegativeInfinity ,
927+ FloatValue6 = 0.0f ,
928+ DoubleValue1 = double . MinValue ,
929+ DoubleValue2 = double . MaxValue ,
930+ DoubleValue3 = double . NaN ,
931+ DoubleValue4 = double . PositiveInfinity ,
932+ DoubleValue5 = double . NegativeInfinity ,
933+ DoubleValue6 = 3.0d ,
934+ DecimalValue1 = decimal . MinValue ,
935+ DecimalValue2 = decimal . MaxValue ,
936+ DecimalValue3 = 1.234567890d ,
937+ } ;
938+
939+ var json = serializer . Serialize ( data ) ;
940+
941+ #if NETFRAMEWORK
942+ json . Should ( ) . Contain ( "\" FloatValue3\" : \" NaN\" " ) ;
943+ json . Should ( ) . Contain ( "\" FloatValue4\" : \" Infinity\" " ) ;
944+ json . Should ( ) . Contain ( "\" FloatValue5\" : \" -Infinity\" " ) ;
945+
946+ json . Should ( ) . Contain ( "\" DoubleValue3\" : \" NaN\" " ) ;
947+ json . Should ( ) . Contain ( "\" DoubleValue4\" : \" Infinity\" " ) ;
948+ json . Should ( ) . Contain ( "\" DoubleValue5\" : \" -Infinity\" " ) ;
949+ #else
950+ // Run JSON roundtrip with System.Text.Json and Newtonsoft.Json
951+ var systemTextJson = System . Text . Json . JsonSerializer . Deserialize < System . Text . Json . JsonElement > ( json , new System . Text . Json . JsonSerializerOptions { NumberHandling = System . Text . Json . Serialization . JsonNumberHandling . AllowNamedFloatingPointLiterals } ) . ToString ( ) ;
952+ var newtonsoftJson = Newtonsoft . Json . JsonConvert . DeserializeObject < Newtonsoft . Json . Linq . JToken > ( json ) . ToString ( Newtonsoft . Json . Formatting . None ) ;
953+
954+ // Deserialize JSON with YamlDotNet
955+ var systemTextJsonResult = deserializer . Deserialize < Dictionary < string , object > > ( systemTextJson ) ;
956+ var newtonsoftJsonResult = deserializer . Deserialize < Dictionary < string , object > > ( newtonsoftJson ) ;
957+
958+ // Assert
959+ systemTextJsonResult . Should ( ) . BeEquivalentTo ( newtonsoftJsonResult ) ;
960+ #endif
961+ }
962+
914963 [ Theory ]
915964 [ InlineData ( typeof ( SByteEnum ) ) ]
916965 [ InlineData ( typeof ( ByteEnum ) ) ]
0 commit comments