-
Notifications
You must be signed in to change notification settings - Fork 5
json.Marshaler implementors not treated unsafe? #9
Copy link
Copy link
Closed
Description
From README.md, things treated as unsafe:
If a type implements the
json.Marshalerorencoding.TextMarshalerinterface (e.g.json.Number).
For encoding.TextMarshaler it seems to hold:
package main
import (
"encoding/json"
"fmt"
)
type Foo int
func (s Foo) MarshalText() (text []byte, err error) {
return []byte("\"foo\""), nil
}
type Bar struct {
X Foo
}
func main() {
x := Bar{X: Foo(0)}
out, _ := json.Marshal(x)
fmt.Println(string(out))
}...gives
foo.go:20:12: Error return value of `encoding/json.Marshal` is not checked: unsafe type `main.Foo` found
However, for json.Marshaler it does not seem to hold; if MarshalText is changed to MarshalJSON in the example, thus making it implement json.Marshaler, no error is provoked. This is with 0.2.2.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels