neuecc / Utf8Json

Definitely Fastest and Zero Allocation JSON Serializer for C#(NET, .NET Core, Unity, Xamarin).
MIT License
2.36k stars 266 forks source link

Can't deserialize decimal in exponent format in some circumstances #85

Open Ephemiere opened 6 years ago

Ephemiere commented 6 years ago

Given:

    public class Test
    {
        [DataMember(Name = "volume")]
        public decimal Volume
        {
            get;
            set;
        }
    }

Utf8Json.JsonSerializer.Deserialize<Test>("{\"volume\":-2.8E-2}");

The deserialization throws an exception: Utf8Json.JsonParsingException: 'expected:',', actual:'E', at offset:14'

This is a contrived case but it's occurring in our production and we have to roll back to Newtonsoft. The corresponding decimal.Parse method returns ok for the give parameter: `decimal.Parse("-2.8E-2", NumberStyles.Float, CultureInfo.InvariantCulture);

Thank you

Ephemiere commented 6 years ago

Looking in Utf8Json.Formatters.DecimalFormatter.Deserialize, if I replace: ArraySegment<byte> arraySegment = reader.ReadNumberSegment(); with ArraySegment<byte> arraySegment = reader.ReadNextBlockSegment(); it seems to work.

phillijw commented 6 years ago

Any update on this? I'm encountering the same issue and looking for a workaround.