fix deserialization: reflect: indirection through nil pointer to embedded struct

This commit is contained in:
yusing
2025-01-21 04:09:46 +08:00
parent dd0bbdc7b4
commit d429374924
2 changed files with 44 additions and 5 deletions

View File

@@ -53,11 +53,23 @@ func TestDeserializeAnonymousField(t *testing.T) {
Anon
C int
}
var s2 struct {
*Anon
C int
}
// all, anon := extractFields(reflect.TypeOf(s2))
// t.Fatalf("anon %v, all %v", anon, all)
err := Deserialize(map[string]any{"a": 1, "b": 2, "c": 3}, &s)
ExpectNoError(t, err)
ExpectEqual(t, s.A, 1)
ExpectEqual(t, s.B, 2)
ExpectEqual(t, s.C, 3)
err = Deserialize(map[string]any{"a": 1, "b": 2, "c": 3}, &s2)
ExpectNoError(t, err)
ExpectEqual(t, s2.A, 1)
ExpectEqual(t, s2.B, 2)
ExpectEqual(t, s2.C, 3)
}
func TestStringIntConvert(t *testing.T) {