mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
Fix unmarshaling struct with interface field which is a pointer to a struct (part 2: test)
This commit is contained in:
@@ -156,3 +156,15 @@ func TestUnderflowArray(t *testing.T) {
|
||||
t.Errorf("Unmarshal(%v) = %+v; want %+v", arrayUnderflowString, a, arrayUnderflowValue)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalStructWithEmbeddedPtrStruct(t *testing.T) {
|
||||
var s = StructWithInterface{Field2: &EmbeddedStruct{}}
|
||||
var err error
|
||||
err = easyjson.Unmarshal([]byte(structWithInterfaceString), &s)
|
||||
if err != nil {
|
||||
t.Errorf("easyjson.Unmarshal() error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(s, structWithInterfaceValueFilled) {
|
||||
t.Errorf("easyjson.Unmarshal() = %#v; want %#v", s, structWithInterfaceValueFilled)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -624,3 +624,17 @@ type RequiredOptionalStruct struct {
|
||||
FirstName string `json:"first_name,required"`
|
||||
Lastname string `json:"last_name"`
|
||||
}
|
||||
|
||||
type StructWithInterface struct {
|
||||
Field1 int `json:"f1"`
|
||||
Field2 interface{} `json:"f2"`
|
||||
Field3 string `json:"f3"`
|
||||
}
|
||||
|
||||
type EmbeddedStruct struct {
|
||||
Field1 int `json:"f1"`
|
||||
Field2 string `json:"f2"`
|
||||
}
|
||||
|
||||
var structWithInterfaceString = `{"f1":1,"f2":{"f1":11,"f2":"22"},"f3":"3"}`
|
||||
var structWithInterfaceValueFilled = StructWithInterface{1, &EmbeddedStruct{11, "22"}, "3"}
|
||||
|
||||
Reference in New Issue
Block a user