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

macro for % JSON serialization #3

Open
brentp opened this issue May 16, 2018 · 2 comments
Open

macro for % JSON serialization #3

brentp opened this issue May 16, 2018 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@brentp
Copy link
Collaborator

brentp commented May 16, 2018

currently any time an attribute is added, the % procs must be updated to include that attribute.

a macro that iterated over the fields and values would simplify this a lot.

@brentp brentp added the help wanted Extra attention is needed label May 16, 2018
@timotheecour
Copy link
Contributor

timotheecour commented Jan 26, 2019

@brentp not sure i understand, but *% from std/json can do that: it can serialize (or reverse: https://nim-lang.github.io/Nim/json.html#overview-unmarshalling) objects and tuples directly, no need to iterate over fields

specifically: this could be replaced by: let foo = %* a IIRC

func `%`*(a: Annotation): JsonNode =
  ## creates a JsonNode from an `Annotations` object depending on the object variant
  result = %[ ("x", %a.x)
            , ("xshift", %a.xshift)
            , ("y", %a.y)
            , ("yshift", %a.yshift)
            , ("text", %a.text)
            , ("showarrow", %a.showarrow)
            ]

@brentp
Copy link
Collaborator Author

brentp commented Jan 26, 2019

I mean, for example, the ones the use ordered fields, as in: https://github.com/brentp/nim-plotly/blob/master/src/plotly/api.nim#L175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants