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

fix #50: add skipHook to skip fields of object when serializing #57

Merged
merged 4 commits into from
Apr 6, 2023

Conversation

pietroppeter
Copy link
Contributor

fix #50 by allowing to declare a skipHook to skip fields. works at compile time.
also added a new test file with a test case and a new hook section in the readme:

proc skipHook*() Can be used to skip fields when serializing an object

If you want to skip some fields when serializing an object you can declare a skipHook*()

type
  Conn = object
    id: int
  Foo = object
    a: int
    password: string
    b: float
    conn: Conn

proc skipHook*(T: typedesc[Foo], key: static string): bool =
  key in ["password", "conn"]

var v = Foo(a:1, password: "12345", b:0.5, conn: Conn(id: 1))
let s = v.toJson()

Gives us:

"{"a":1,"b":0.5}"

@pietroppeter
Copy link
Contributor Author

(alternative to #51)

@treeform
Copy link
Owner

I think your PR fails to due to issue: nim-lang/Nim#21317

@ringabout
Copy link

fixed => nim-lang/Nim#21320

@pietroppeter
Copy link
Contributor Author

If CI is approved I would expect it now to be green. I also fixed the conflict with master.

@pietroppeter
Copy link
Contributor Author

CI is green and no conflicts with master. Any thoughts?

@treeform treeform merged commit d627a0e into treeform:master Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Easy way to skip fields of an object
3 participants