Easy way to skip fields of an object
creikey opened this issue · comments
Say I have an object like this:
Player = ref object
username: string
ready: bool
conn: WebSocket
curLevel: JsonNode
invadingUsername: string
heistSuccess: bool
id: uint64
that I want to dump to json, but don't want the conn
to be in the dumped json. What if jsony had some kind of skipHook you could define to describe what fields to skip serializing?
Beef on the discord advocates for a skip pragma like this:
import std/macros
...
for name, field in object
when not field.hasCustomPragma(jsonSkip):
## serializer
and a template like this: template jsonySkip*{.pragma.}
with conn {.jsonySkip.}: WebSocket