Support custom unmarshallers for interface types#843
Open
wrouesnel wants to merge 1 commit into
Open
Conversation
The custom unmarshaller code did not handle being
passed a nil interface properly, meaning doing so
would lead to "nil" being assigned an unmarshaller
and the interface type not being.
This patch fixes this to allow interface types to
have custom unmarshallers assigned, which allows
code like:
```
type S struct {
X SomeInterface
}
```
to be detected and unmarshalled using a custom
unmarshaller.
It should be noted that direct variables must be
passed by address to be detected e.g.
```
var S SomeInterface
yaml.Unmarshal(bytes, &S)
```
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #843 +/- ##
=======================================
Coverage 80.48% 80.49%
=======================================
Files 22 22
Lines 6846 6849 +3
=======================================
+ Hits 5510 5513 +3
Misses 914 914
Partials 422 422 🚀 New features to boost your workflow:
|
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.
The custom unmarshaller code did not handle being passed a nil interface properly, meaning doing so would lead to "nil" being assigned an unmarshaller and the interface type not being.
This patch fixes this to allow interface types to have custom unmarshallers assigned, which allows code like:
to be detected and unmarshalled using a custom unmarshaller.
It should be noted that direct variables must be passed by address to be detected e.g.
The specific utility of this code is that it provides the ability to set custom serialization for types with interface members such that they can be directly unmarshalled back to the interface (for example, by using a discriminant enum).