# Erm... question regarding jsony and providing default values for datetime # fields. # I have a JSON string that is missing some fields (creation_datetime and # update_datetime). # I want to provide default values for those. Jsony tells you to write a `newHook` # proc to assign those values. # I've done so, but I'm getting `SIGSEGV: Illegal storage access. (Attempt to read # from nil?)` in that proc somehow and I don't get how. import std/[typetraits, times] import norm/[pragmas, model] import jsony const OUTPUT_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'.'ffffff'Z'" type Character {.tableName: "wikientries_character".} = ref object of Model name: string creation_datetime: DateTime update_datetime: DateTime proc parseHook(s: string, i: var int, v: var DateTime) = ##[ jsony-hook that is automatically called to convert a json-string to datetime ``s``: The full JSON string that needs to be serialized. Your type may only be a part of this ``i``: The index on the JSON string where the next section of it starts that needs to be serialized here ``v``: The variable to fill with a proper value]## var str: string s.parseHook(i, str) v = parse(s, OUTPUT_TIME_FORMAT, utc()) proc newHook(entry: var Character) = let currentDateTime: DateTime = now() entry.creation_datetime = currentDateTime # <-- This line is listed as the reason for the sigsev entry.update_datetime = currentDateTime entry.name = "" var input = """ {"name":"Test"} """ let c = input.fromJson(Character) # Does anyone spot the issue?