Unmarshalling with embedded structs is failing
badarsebard opened this issue · 1 comments
badarsebard commented
This is a similar issue to what was happening in #142. Tags aren't being managed properly when using embedded structs.
Example from internal/encoding_test.go
:
When the Base
struct tag is changed from the empty string (such as _id
), it fails to be managed correctly with the current version and the ID
is lost when calling Convert
. This causes the TestNormalize
test to fail at line79.
type BaseModel struct {
ID string `clover:"_id"`
}
type TestStruct struct {
BaseModel
IntField int `clover:"int,omitempty"`
UintField uint `clover:"uint,omitempty"`
StringField string `clover:",omitempty"`
FloatField float32 `clover:",omitempty"`
BoolField bool `clover:",omitempty"`
TimeField time.Time `clover:",omitempty"`
IntPtr *int `clover:",omitempty"`
SliceField []int `clover:",omitempty"`
MapField map[string]interface{} `clover:",omitempty"`
Data []byte `clover:",omitempty"`
}
Adding json
tags also fails.
The issue is due to how the createRenameMap
function iterates through the fields of the struct. I am submitting a PR that adds a recursive call to the function when the field type is anonymous so the fields of embedded structs will be included.
badarsebard commented
Fixed with #152