forked from mirror/go-json
Merge pull request #378 from orisano/fix/#372
Fix embedded primitive type encoding using alias
This commit is contained in:
commit
554506d1f4
|
@ -3968,3 +3968,20 @@ func TestIssue335(t *testing.T) {
|
||||||
t.Errorf("unexpected success")
|
t.Errorf("unexpected success")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIssue372(t *testing.T) {
|
||||||
|
type A int
|
||||||
|
type T struct {
|
||||||
|
_ int
|
||||||
|
*A
|
||||||
|
}
|
||||||
|
var v T
|
||||||
|
err := json.Unmarshal([]byte(`{"A":7}`), &v)
|
||||||
|
assertErr(t, err)
|
||||||
|
|
||||||
|
got := *v.A
|
||||||
|
expected := A(7)
|
||||||
|
if got != expected {
|
||||||
|
t.Errorf("unexpected result: %v != %v", got, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -393,6 +393,15 @@ func compileStruct(typ *runtime.Type, structName, fieldName string, structTypeTo
|
||||||
}
|
}
|
||||||
allFields = append(allFields, fieldSet)
|
allFields = append(allFields, fieldSet)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
fieldSet := &structFieldSet{
|
||||||
|
dec: pdec,
|
||||||
|
offset: field.Offset,
|
||||||
|
isTaggedKey: tag.IsTaggedKey,
|
||||||
|
key: field.Name,
|
||||||
|
keyLen: int64(len(field.Name)),
|
||||||
|
}
|
||||||
|
allFields = append(allFields, fieldSet)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fieldSet := &structFieldSet{
|
fieldSet := &structFieldSet{
|
||||||
|
|
Loading…
Reference in New Issue