I have two structs. One inherits from the other.
type Animal struct {
Name string `json:"name"`
}
type Dog struct {
Animal
Color string `json:"color"`
}
When I go to Unmarshal
to Dog
by passing in:
{
"name": "Loki",
"color": "Brown"
}
I'm getting an *encoding/json.InvalidUnmarshalError
. 2019/03/10 00:22:35 json: Unmarshal(nil *main.Dog)
Why is that?
Here's the unmarshal code:
func main() {
var dog *Dog
err := json.Unmarshal([]byte(`{
"name": "Loki",
"color": "Brown"
}`), dog)
if err != nil {
log.Fatal(err)
}
}