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

extend skipHook to skip object fields based on values #85

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

georgelemon
Copy link

tests included

Signed-off-by: George Lemon <georgelemon@protonmail.com>
@pietroppeter
Copy link
Contributor

Great idea! I guess an example in the Readme would also be welcome, so that the feature is discoverable (I am not the maintainer)

Signed-off-by: George Lemon <georgelemon@protonmail.com>
@georgelemon
Copy link
Author

georgelemon commented Apr 2, 2024

The best use case scenario is when working with APIs. I want to use jsony to serialize/deserialize objects in requests & responses. For example

type
  Product = object 
    id, slug: string          # filled by the server
    published: bool
    title, content: string

When making a POST request, I can't send an object that contains an emptyid field (or slug), because those fields are available in a GET request, so most probably I will get an error from the server. Reusing the same Nim object and stripping fields based on their values would be possible with the runtime skipHook

Signed-off-by: George Lemon <georgelemon@protonmail.com>
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.

2 participants