You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Serializing and deserializing Double.MaxValue works in general:
openSystemopenThoth.Json.Net
Encode.float Double.MaxValue |> Encode.toString 0|> Decode.fromString Decode.float
valit:Result<float,string>=Ok 1.797693135e+308match it with Ok f -> f = System.Double.MaxValue | Error e -> failwith "error"valit:bool =true
But in our case we are storing the JSON in a Postgres database in a JSONB-column. Postgres uses the numeric type for numeric JSON values. Fetching the JSON from the database and deserializing it with Thoth.Json leads to a problem:
letmaxFloat="179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"valmaxFloat:string ="1797693134862315700000000000000000000000000000000000000000000"+[248 chars]match Decode.fromString Decode.float maxFloat with Ok f -> f = Double.MaxValue | Error e -> failwith "error"
System.InvalidCastException: Object must implement IConvertible.
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at Newtonsoft.Json.Linq.Extensions.Convert[T,U](T token)
at Newtonsoft.Json.Linq.Extensions.Value[T,U](IEnumerable`1 value)
at Newtonsoft.Json.Linq.Extensions.Value[U](IEnumerable`1 value)
at Thoth.Json.Net.Decode.float(String path, JToken token)
at Thoth.Json.Net.Decode.fromValue[T](String path, FSharpFunc`2 decoder, JToken value)
at Thoth.Json.Net.Decode.fromString[T](FSharpFunc`2 decoder, String value)
at <StartupCode$FSI_0026>.$FSI_0026.main@()in C:\stdin:line 3
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
Aufgrund eines Fehlers beendet
Several other methods to deserialize this value to float worked:
So I consider this a bug, although I would be happier if postgres just returned the value in exponential notation. Please note that the value doesn't need to be that high, it fails also for smaller inputs. It seems somewhere in the loop the value is deserialized as BigInteger, which doesn't implement IConvertible.
The text was updated successfully, but these errors were encountered:
Serializing and deserializing Double.MaxValue works in general:
But in our case we are storing the JSON in a Postgres database in a JSONB-column. Postgres uses the numeric type for numeric JSON values. Fetching the JSON from the database and deserializing it with Thoth.Json leads to a problem:
Several other methods to deserialize this value to float worked:
So I consider this a bug, although I would be happier if postgres just returned the value in exponential notation. Please note that the value doesn't need to be that high, it fails also for smaller inputs. It seems somewhere in the loop the value is deserialized as BigInteger, which doesn't implement IConvertible.
The text was updated successfully, but these errors were encountered: