Skip to content

Support custom unmarshallers for interface types#843

Open
wrouesnel wants to merge 1 commit into
goccy:masterfrom
wrouesnel:wrouesnel_interface_marshallers
Open

Support custom unmarshallers for interface types#843
wrouesnel wants to merge 1 commit into
goccy:masterfrom
wrouesnel:wrouesnel_interface_marshallers

Conversation

@wrouesnel

Copy link
Copy Markdown

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)

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).

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-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.49%. Comparing base (92bc79c) to head (79d5895).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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