objconv
objconv copied to clipboard
Unmarshaling JSON into embedded structs doesn't work
This test tries to deserialize JSON input into a struct which embeds another. There are two parts to this test:
- use normal encoding/json
- use objconv/json
The test fails on the objconv part:
import (
"encoding/json"
"testing"
convjson "github.com/segmentio/objconv/json"
)
func TestObjConv(t *testing.T) {
type inner struct {
Value int64
}
type outer struct {
inner
}
input := `{"value":42}`
var res outer
err := json.Unmarshal([]byte(input), &res)
if err != nil {
t.Fatal(err)
}
if res.Value != int64(42) {
t.Fatal(res.Value)
}
res = outer{}
err = convjson.Unmarshal([]byte(input), &res)
if err != nil {
t.Fatal(err)
}
if res.Value != int64(42) {
t.Fatal(res.Value)
}
}