For example, the default value of double (which is a NaN) is serialized to null, which throws an error when attempting to deserialize:
/+dub.sdl:
dependency "vibe-serialization" version="*"
+/
import std.stdio;
import vibe.data.json;
void main() {
double d;
d.serializeToJsonString .writeln; // prints "null"
d.serializeToJsonString.deserializeJson!double.writeln; // throws
}
I think serialization libraries should try to ensure that a serialization and deserialization round-trip does not have such surprises.
We could do one of:
- Throw on serialization if the value is not deserializable;
- Serialize as a string (e.g.
"NaN") and recognize it when deserializing
- If it's just NaN, then understand
null as NaN (but not sure about infinities).