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

Incorrect timespan serialization #100

Open epeshk opened 6 years ago

epeshk commented 6 years ago

Serialization of TimeSpan that respresent interval less than 100 milliseconds gives wrong result.

var ts = TimeSpan.FromMilliseconds(99);
Console.WriteLine(Utf8Json.JsonSerializer.ToJsonString(ts));

Expected: "00:00:00.0990000" Actual: "00:00:00.990000" (990 ms, not 99)

this problem can be temporarily fixed in user app with following code:

CompositeResolver.RegisterAndSetAsDefault(
    new[]{new TimeSpanFormatter()},
    new[]{StandardResolver.Default});

This issue maybe related to https://github.com/neuecc/Utf8Json/issues/80

epeshk commented 6 years ago

PR: https://github.com/neuecc/Utf8Json/pull/101