-
Notifications
You must be signed in to change notification settings - Fork 13
json.Unmarshaler interface not considered for nested types #93
Copy link
Copy link
Closed
Description
I believe I may have found a false positive. The following minimum reproduction shows the false positive:
package main
import (
"encoding/json"
"fmt"
)
type Outer struct {
Inner Inner `json:"inner"`
}
type Inner struct {
String string
}
func (i *Inner) UnmarshalJSON(p []byte) error {
var s string
if err := json.Unmarshal(p, &s); err != nil {
return err
}
i.String = s
return nil
}
func main() {
buf := []byte(`
{
"inner": "my string"
}
`)
var outer Outer
if err := json.Unmarshal(buf, &outer); err != nil {
panic(err)
}
fmt.Println(outer)
}
The output of the program is:
{{my string}}
See https://go.dev/play/p/HEcyBYmfO_Y
However, musttag with the latest tag (v0.12.1) shows a false positive:
main.go:32:32: the given struct should be annotated with the `json` tag
It doesn't seem to ignore the absence of JSON tags on the Inner type, even though the Inner type implements the jsonUnmarshaler interface.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels