-
Notifications
You must be signed in to change notification settings - Fork 6
Closed
Description
From README.md, things treated as unsafe:
If a type implements the
json.Marshaler
orencoding.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.
breml
Metadata
Metadata
Assignees
Labels
No labels