JamesNK / Newtonsoft.Json

Json.NET is a popular high-performance JSON framework for .NET
https://www.newtonsoft.com/json
MIT License
10.64k stars 3.24k forks source link

Serialized C# class numeric string is partially converted to float on serialization and deserialization (used to be fine) version 13.0.0.0 #2949

Closed hipparchus2000 closed 2 months ago

hipparchus2000 commented 2 months ago

Source/destination types

// Put the types you are serializing or deserializing here

String property of an object
Note same thing happens on serialization and deserialization with current nuget version.
JsonSoft converter should know it's going into a string property , so why involve and numeric conversion at all? 

Assert.AreEqual failed. Expected:<01107587500061821719090611180906104444>. Actual:<011.07588E+131719090611180906104444>

Source/destination JSON

{"message":"Place your serialized or deserialized JSON here"}

Correct "expectedBarcodeBString": "01107587500061821719090611180906104444", Incorrect "expectedBarcodeBString": "011.07588E+131719090611180906104444",

Expected behavior

String property "01107587500061821719090611180906104444" to be serialized and deserialized as "01107587500061821719090611180906104444"

Actual behavior

Newtonsoft jsonconverted partly converts the numeric string to a float: 011.07588E+131719090611180906104444

Steps to reproduce



//barcodeTestResultsList has a property of type string with "01107587500061821719090611180906104444" in it.

                JsonSerializer serializer = new JsonSerializer();
                using (StreamWriter sw = new StreamWriter(@"c:\\temp\\barcodeTestResults.json"))
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, barcodeTestResultsList);
                }
elgonzo commented 2 months ago

Not reproducible.

Using Newtonsoft.Json 13.0.3 and your example code (swapping StreamWriter with Console.Out and making my own class for barcodeTestResultsList), the string is being correctly serialized unaltered: https://dotnetfiddle.net/2v328g

hipparchus2000 commented 2 months ago

deepest apologies, the bug is in imported data.