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

Excluding known typed fields from returned map #16

Closed
thedenisnikulin opened this issue Aug 22, 2022 · 3 comments · Fixed by #20
Closed

Excluding known typed fields from returned map #16

thedenisnikulin opened this issue Aug 22, 2022 · 3 comments · Fixed by #20
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@thedenisnikulin
Copy link

thedenisnikulin commented Aug 22, 2022

It would be great if there was an option that excludes from resulting map[string]interface{} the fields that were unmarshalled to the struct object, see the example below:

v := struct {
	Foo string `json:"foo"`
	Boo []int  `json:"boo"`
}{}
result, err := marshmallow.Unmarshal([]byte(`{"foo":"bar","boo":[1,2,3],"goo":12.6}`), &v)
fmt.Printf("v=%+v, result=%+v, err=%v", v, result, err)
// Output: v={Foo:bar Boo:[1 2 3]}, result=map[goo:12.6], err=<nil>
//                                  ^^^^^^     ^^^
// only "goo" field is present in result since "foo" and "boo" are explicitly typed
@avivpxi
Copy link
Collaborator

avivpxi commented Aug 22, 2022

Yes, @thedenisnikulin, it seems reasonable and should be quite easy to add.

We will be able to get to it in the upcoming weeks.
At the meantime, if you're interested in submitting a PR yourself, that would be appreciated

@avivpxi avivpxi added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Aug 22, 2022
@thedenisnikulin
Copy link
Author

Great, thanks!

@avivpxi avivpxi linked a pull request Aug 29, 2022 that will close this issue
@avivpxi
Copy link
Collaborator

avivpxi commented Aug 31, 2022

@thedenisnikulin support for excluding known fields is released in v1.1.3
Example can be found here.
Thanks @galepx and @itayPX for moving fast with this one 👑 🙏

Playground link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants