Closed sylvainrodrigue closed 2 months ago
I am not commenting on whether this is an accidental regression or an intenional fix/change in the behavior of the serializer, but take note that your examples are not valid json. The json format does not allow numbers featuring a decimal dot without a preceding numerical digit. As such, expect that your kind-of-but-not-really json will cause further problems if you ever decide to use something else than Newtonsoft.Json...
You're right: this is not supported by JSON. So this is a fix, not a regression. The problem is our side. Thank you for your quick reply, much appreciated!
Source/destination types
Source/destination JSON
Expected behavior
Actual behavior
Both examples throw an exception with NewtonSoft 10.0.1 or higher. Both works with 9.0.1 or lower.
Exception thrown:
Newtonsoft.Json.JsonReaderException HResult=0x80131500 Message=Input string '.00' is not a valid decimal. Path 'Amount', line 1, position 15. Source=Newtonsoft.Json StackTrace: at Newtonsoft.Json.JsonTextReader.ParseReadNumber(ReadType readType, Char firstChar, Int32 initialPosition) at Newtonsoft.Json.JsonTextReader.ParseNumber(ReadType readType) at Newtonsoft.Json.JsonTextReader.ReadNumberValue(ReadType readType) at Newtonsoft.Json.JsonTextReader.ReadAsDecimal() at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value) at NewtonSoft_Test2.Program.Main(String[] args) in C:\Repos_Test\NewtonSoft_Test2\NewtonSoft_Test2\Program.cs:line 17
Steps to reproduce