mapstructure
mapstructure copied to clipboard
Fix Encoding Struct Back to Map Bug (#279)
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:
- Unit test to decode struct (with remain-field) to map.
- Unit test to check invalid remain-field type check error.
- Example test to decode
map -> struct -> map. - 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
Pulled in at https://github.com/go-viper/mapstructure/pull/8