Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] LiteDB.JsonSerializer.Deserialize - exception for double in scientific notation #1777

Closed
ConiJB opened this issue Aug 6, 2020 · 2 comments
Labels

Comments

@ConiJB
Copy link

ConiJB commented Aug 6, 2020

Version
LiteDB 5.0.8/ Win 10/ .NET Core 3.1

Describe the bug
When deserializing a json string containing a double in scientific notation (e.g. "{ 'DoubleValue': 2E-05 }") to a BsonDocument, LiteDB.JsonSerializer.Deserialize throws a System.FormatException with "Input string was not in a correct format."

Code to Reproduce

 var json = @"{ 'DoubleValue': 2E-05 }";
 var doc = LiteDB.JsonSerializer.Deserialize(json).AsDocument;

Expected behavior
A BsonDocument containing a key "DoubleValue" with a value (type double) of 0.00002

Screenshots/Stacktrace
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at System.Number.ParseInt32(ReadOnlySpan`1 value, NumberStyles styles, NumberFormatInfo info)
at System.Convert.ToInt32(String value, IFormatProvider provider)
at LiteDB.JsonReader.ReadValue(Token token)
at LiteDB.JsonReader.ReadObject()
at LiteDB.JsonReader.ReadValue(Token token)
at LiteDB.JsonReader.Deserialize()
at LiteDB.JsonSerializer.Deserialize(String json)

Additional context
If you add "dbl = true;" in LiteDB.Tokenizer in ReadNumber(ref bool dbl) where _char is checked for 'e' (see screenshot) it solved it for me - doubles were deserialized like a charm. Would you consider that as a fix?

grafik

@lbnascimento
Copy link
Collaborator

@ConiJB Thanks for your contribution. This issue has been fixed in the master and its fix will be present in the next incremental release.

@ConiJB
Copy link
Author

ConiJB commented Aug 6, 2020

Thank you for that very fast and positive response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants