Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unmarshalling with embedded structs is failing #151

Closed
badarsebard opened this issue May 25, 2024 · 1 comment
Closed

Unmarshalling with embedded structs is failing #151

badarsebard opened this issue May 25, 2024 · 1 comment

Comments

@badarsebard
Copy link
Contributor

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
Copy link
Contributor Author

Fixed with #152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant