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 Encoding Struct Back to Map Bug (#279) #307

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vaguecoder
Copy link

Motivation

Issue #279 reported by @kszafran

Changes

Check in decode struct -> map for extra fields encoded with remain tag, and flatten in resultant map. Add corresponding tests:

  1. Unit test to decode struct (with remain-field) to map.
  2. Unit test to check invalid remain-field type check error.
  3. Example test to decode map -> struct -> map.
  4. Benchmark test to decode map -> struct -> map.

Summary

As extra fields are added to the remain-field while decoding map as structure, the reverse should work as well. i.e., while decoding structure as map, the extra fields in remain-field should get flattened in previous level. For code example, refer #279.

Related Issues

Closes #279

Signed-off-by: Bhargav Ravuri <vaguecoder0to.n@gmail.com>
@sagikazarmark
Copy link

Pulled in at go-viper#8

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.

Encode a struct with ",remain" back to a map?
2 participants