Skip to content

Conversation

@sagikazarmark
Copy link
Member

@sagikazarmark sagikazarmark commented Jan 12, 2026

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

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
@sagikazarmark sagikazarmark requested a review from Copilot January 12, 2026 17:12
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Unmarshaler interface with UnmarshalMapstructure(any) error method
  • Integrated Unmarshaler check into the decode flow (runs after DecodeHook but before standard decoding)
  • Added DisableUnmarshaler config 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.

@sagikazarmark sagikazarmark merged commit 9aa3f77 into main Jan 12, 2026
11 checks passed
@sagikazarmark sagikazarmark deleted the unmarshal2 branch January 12, 2026 17:24
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.

2 participants