mapstructure icon indicating copy to clipboard operation
mapstructure copied to clipboard

Fix Encoding Struct Back to Map Bug (#279)

Open vaguecoder opened this issue 3 years ago • 1 comments

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

vaguecoder avatar Oct 02 '22 19:10 vaguecoder

Pulled in at https://github.com/go-viper/mapstructure/pull/8

sagikazarmark avatar Dec 18 '23 18:12 sagikazarmark