Closed garfeng closed 2 years ago
type BasicModel struct { ID string `clover:"_id" json:"_id"` } type User struct { BasicModel Name string `clover:"name" json:"name"` } func TestAnonymousField(t *testing.T) { user := &User{ Name: "Alice", } user.ID = "UUUU-UUUU-UUUU" doc := clover.NewDocumentOf(user) docMap := map[string]interface{}{} doc.Unmarshal(&docMap) buff, _ := json.MarshalIndent(docMap, "", " ") fmt.Println(string(buff)) /* { "BasicModel": { "_id": "UUUU-UUUU-UUUU" }, "name": "Alice" } */ user2 := &User{} doc.Unmarshal(user2) fmt.Println(user2.ID) // "", empty }
With my commit, the buff will be like :
{ "_id": "UUUU-UUUU-UUUU", "name": "Alice" }
I will add it soon. @ostafen
With my commit, the buff will be like :