From README.md, things treated as unsafe:
If a type implements the json.Marshaler or encoding.TextMarshaler interface (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.
From README.md, things treated as unsafe:
For
encoding.TextMarshalerit seems to hold:...gives
However, for
json.Marshalerit does not seem to hold; ifMarshalTextis changed toMarshalJSONin the example, thus making it implementjson.Marshaler, no error is provoked. This is with 0.2.2.