Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easy way to skip fields of an object #50

Closed
creikey opened this issue Jul 19, 2022 · 1 comment · Fixed by #57
Closed

Easy way to skip fields of an object #50

creikey opened this issue Jul 19, 2022 · 1 comment · Fixed by #57

Comments

@creikey
Copy link

creikey commented Jul 19, 2022

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?

@creikey
Copy link
Author

creikey commented Jul 19, 2022

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

treeform added a commit that referenced this issue Apr 6, 2023
fix #50: add skipHook to skip fields of object when serializing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant