neuecc / Utf8Json

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

ArrayFormatter<double> doesn't handle Infinity well #89

Open ghost opened 6 years ago

ghost commented 6 years ago

Though Utf8Json has implemented code to deal with double.Infinite, when trying to deserialize an json array(contains Infinite value) to ExpandoObject, exception is thrown.

The reason is that ReadIsValueSeparatorWithVerify() only allows comma(,). When JsonReader meets "Infinity", ReadIsValueSeparatorWithVerify() is called before ReadDouble().

var input = "{\"array\":[1.1,Infinity,2.0]}"
JsonSerializer.Deserialize<dynamic>(input);
JsonParsingException: expected:',', actual:'I', at offset:14
at void Utf8Json.JsonReader.ReadIsValueSeparatorWithVerify ()
at bool Utf8Json.JsonReader.ReadIsEndArrayWithSkipValueSeparator (ref int count)
at object Utf8Json.Formatters.PrimitiveObjectFormatter.Deserialize (ref JsonReader reader, IJsonFormatterResolver formatterResolver)
at object Utf8Json.Formatters.PrimitiveObjectFormatter.Deserialize (ref JsonReader reader, IJsonFormatterResolver formatterResolver)
at T Utf8Json.JsonSerializer.Deserialize<T> (byte[] bytes, int offset, IJsonFormatterResolver resolver)
at void <<Initialize>>d__0.MoveNext ()
at void System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw ()
at void System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task task)
at void Xamarin.Interactive.CodeAnalysis.EvaluationContext.<CoreRunAsync>d__27.MoveNext () in EvaluationContext.cs:234
at void System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw ()
at void System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task task)
at void Xamarin.Interactive.CodeAnalysis.EvaluationContext.<RunAsync>d__26.MoveNext () in EvaluationContext.cs:147