JsonSerializer.Deserialize errors when encountering Long datatype
Code to reproduce issue:
var reqString = $"{{\"id\": {long.MaxValue} }}";
var test = JsonSerializer.Deserialize(reqString);
The issue can be found in LiteDB\Serializer\Json\JsonReader.cs - ReadValue(JsonToken token). The switch statement chooses JsonTokenType.Number, and because of the lack of ".", tries to convert the value to an Int32. Because the value is too big, it throws and overflow exception.
By default, JSON specs supports only int. To use long number you need "JSON long representation". {"id":{"$numberLong":"123456789"}}
https://github.com/mbdavid/LiteDB/blob/master/LiteDB/Serializer/Json/JsonReader.cs#L159
Unfortunately, this solution is not very convenient in practice. In particular, now I have a need to save in DB json which I receive from the server as a string. And now, unexpectedly, I began to get a System.OverflowException.
It would be much better if the already built-in JsonSerializer could automatically use int64 if the value does not fit in int32. And double if the value does not fit in int64. And do not throw an exception.
But since this is not the case, I will have to write "my" JsonSerializer which can do this.