Calling Nakama.TinyJson.JsonWriter.ToJson on an object with a DateTime will crash

string f = Nakama.TinyJson.JsonWriter.ToJson(DateTime.UtcNow);

This call with crash with:
An unhandled exception of type ‘System.StackOverflowException’ occurred in mscorlib.dll.

Ran into this while I was about to add some objects to the Nakama collection storage that had DateTime properties in them. I could use a Newtonsoft json parser to convert these instead but if I didn’t have to add another dependency that would be nice.

TinyJson is intended to be a compact and resource-efficient JSON encoder/decoder so it doesn’t quite handle every type.

It’s probably easiest to just convert your DateTime type to a string notation like ISO 8601 or an integer representing UTC seconds/milliseconds before passing it to be encoded as JSON.

1 Like