treeform / jsony

A loose, direct to object json parser with hooks.
MIT License
270 stars 34 forks source link

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

Closed pietroppeter closed 1 year ago

pietroppeter commented 1 year ago

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 commented 1 year ago

(alternative to #51)

treeform commented 1 year ago

I think your PR fails to due to issue: https://github.com/nim-lang/Nim/issues/21317

ringabout commented 1 year ago

fixed => https://github.com/nim-lang/Nim/pull/21320

pietroppeter commented 1 year ago

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

pietroppeter commented 1 year ago

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