Merged
Conversation
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
There was a problem hiding this comment.
Pull request overview
This pull request adds an Unmarshaler interface to mapstructure, allowing types to define custom unmarshaling behavior similar to json.Unmarshaler from the standard library. This is a follow-up to previous PRs (#11, #155, #164) with improved edge case handling and test quality.
Changes:
- Added
Unmarshalerinterface withUnmarshalMapstructure(any) errormethod - Integrated Unmarshaler check into the decode flow (runs after DecodeHook but before standard decoding)
- Added
DisableUnmarshalerconfig option to opt out of Unmarshaler behavior - Comprehensive test coverage including nested structs, embedding, non-struct types, error handling, and interaction with DecodeHook
- Added example demonstrating default value application via Unmarshaler
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| mapstructure.go | Core implementation: defines Unmarshaler interface, adds DisableUnmarshaler config option, implements getUnmarshaler helper, and integrates Unmarshaler check into decode flow |
| mapstructure_test.go | Comprehensive test suite covering basic usage, DecodeHook interaction, disable flag, nested structs, embedding, error handling, pointer receivers, non-struct types (string, slice, map), metadata, and struct-to-map decoding |
| mapstructure_examples_test.go | Example demonstrating Unmarshaler interface usage for applying default values |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
radermacher-iits
pushed a commit
to kubara-io/kubara
that referenced
this pull request
Feb 19, 2026
…5.0 (#232) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/go-viper/mapstructure/v2](https://github.com/go-viper/mapstructure) | require | minor | `v2.4.0` → `v2.5.0` | --- ### Release Notes <details> <summary>go-viper/mapstructure (github.com/go-viper/mapstructure/v2)</summary> ### [`v2.5.0`](https://github.com/go-viper/mapstructure/releases/tag/v2.5.0) [Compare Source](go-viper/mapstructure@v2.4.0...v2.5.0) #### What's Changed - Print qualified type name when ErrorUnused=true causes errors for unused keys in embedded fields by [@​jmacd](https://github.com/jmacd) in [#​113](go-viper/mapstructure#113) - build(deps): bump github/codeql-action from 3.29.2 to 3.29.5 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​126](go-viper/mapstructure#126) - build(deps): bump github/codeql-action from 3.29.7 to 3.29.10 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​131](go-viper/mapstructure#131) - build(deps): bump actions/checkout from 4.2.2 to 5.0.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​129](go-viper/mapstructure#129) - feat: support for automatically initializing squashed pointer structs by [@​tuunit](https://github.com/tuunit) in [#​71](go-viper/mapstructure#71) - build(deps): bump actions/setup-go from 5.5.0 to 6.0.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​134](go-viper/mapstructure#134) - build(deps): bump ossf/scorecard-action from 2.4.2 to 2.4.3 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​142](go-viper/mapstructure#142) - Fix slice deep map (owned) by [@​jphastings](https://github.com/jphastings) in [#​144](go-viper/mapstructure#144) - chore: fix lint violations by [@​sagikazarmark](https://github.com/sagikazarmark) in [#​157](go-viper/mapstructure#157) - chore: switch to devenv by [@​sagikazarmark](https://github.com/sagikazarmark) in [#​158](go-viper/mapstructure#158) - build(deps): bump actions/upload-artifact from 4.6.2 to 5.0.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​151](go-viper/mapstructure#151) - build(deps): bump github/codeql-action from 3.29.10 to 4.31.2 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​153](go-viper/mapstructure#153) - build(deps): bump golangci/golangci-lint-action from 8.0.0 to 9.0.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​154](go-viper/mapstructure#154) - build(deps): bump actions/checkout from 5.0.0 to 6.0.1 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​160](go-viper/mapstructure#160) - build(deps): bump actions/setup-go from 6.0.0 to 6.1.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​159](go-viper/mapstructure#159) - build(deps): bump github/codeql-action from 4.31.7 to 4.31.8 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​162](go-viper/mapstructure#162) - build(deps): bump actions/upload-artifact from 5.0.0 to 6.0.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​161](go-viper/mapstructure#161) - build(deps): bump github/codeql-action from 4.31.8 to 4.31.9 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​163](go-viper/mapstructure#163) - feature: Add map field name to convert structs dynamically instead of individually with a tag. by [@​thespags](https://github.com/thespags) in [#​149](go-viper/mapstructure#149) - feat(decoder): support multiple tag names in order by [@​DarkiT](https://github.com/DarkiT) in [#​59](go-viper/mapstructure#59) - feat: optional root object name by [@​andreev-fn](https://github.com/andreev-fn) in [#​137](go-viper/mapstructure#137) - Add unmarshaler interface by [@​sagikazarmark](https://github.com/sagikazarmark) in [#​166](go-viper/mapstructure#166) #### New Contributors - [@​jmacd](https://github.com/jmacd) made their first contribution in [#​113](go-viper/mapstructure#113) - [@​tuunit](https://github.com/tuunit) made their first contribution in [#​71](go-viper/mapstructure#71) - [@​jphastings](https://github.com/jphastings) made their first contribution in [#​144](go-viper/mapstructure#144) - [@​thespags](https://github.com/thespags) made their first contribution in [#​149](go-viper/mapstructure#149) - [@​DarkiT](https://github.com/DarkiT) made their first contribution in [#​59](go-viper/mapstructure#59) - [@​andreev-fn](https://github.com/andreev-fn) made their first contribution in [#​137](go-viper/mapstructure#137) **Full Changelog**: <go-viper/mapstructure@v2.4.0...v2.5.0> </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi44MC4xIiwidXBkYXRlZEluVmVyIjoiNDIuODAuMSIsInRhcmdldEJyYW5jaCI6Im1hc3RlciIsImxhYmVscyI6W119--> Reviewed-on: https://kubara.git.onstackit.cloud/STACKIT/kubara/pulls/232
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on the PRs below. I opted for creating a new PR, because some of the edge cases weren't handled and tests were AI slob.
Fixes #11
Fixes #155
Fixes #164