You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
type A struct {
BS []B
}
type B struct {
C
}
type C struct {
Index int
}
func (c C) String() string {
return fmt.Sprint("index", c.Index)
}
func main() {
mapper := mapify.Mapper{}
mapper.MapValue = func(path string, e mapify.Element) (any, error) {
fmt.Println("path:", path)
return e.Value.Interface(), nil
}
a := A{}
a.BS = []B{B{C{Index:1}},B{C{Index:2}}}
fmt.Println(mapper.MapAny(a))
}
type A struct {
BS []*B
}
type B struct {
C
}
type C struct {
Index int
}
func (c C) String() string {
return fmt.Sprint("index", c.Index)
}
func main() {
mapper := mapify.Mapper{}
mapper.MapValue = func(path string, e mapify.Element) (any, error) {
fmt.Println("path:", path)
return e.Value.Interface(), nil
}
a := A{}
a.BS = []*B{&B{C{Index:1}},&B{C{Index:2}}}
fmt.Println(mapper.MapAny(a))
}
@anpic I confirm, that mapping of slices of pointers is not implemented at all. Thank you for finding this out! The reason why this is not implemented is pretty simple - I don't use such slices, so I never wanted such feature :) But I admit, that some people may want to use them and that this feature should be implemented.
So far, in the PR, I have added support for slices of pointers to structs. But there are other types of pointers like []*map or []*[]string, which should be supported as well, I guess. It will take some time to finish the implementation, so I marked the PR as a draft (work in progress). I will let you know when it is finished.
Activity
elgopher commentedon Jan 15, 2026
thank you @anpic for reporting a bug! Somehow I missed the notification about it. I will look at the issue in the evening.
elgopher commentedon Jan 15, 2026
@anpic I confirm, that mapping of slices of pointers is not implemented at all. Thank you for finding this out! The reason why this is not implemented is pretty simple - I don't use such slices, so I never wanted such feature :) But I admit, that some people may want to use them and that this feature should be implemented.
I've created a PR with the fix: #12
So far, in the PR, I have added support for slices of pointers to structs. But there are other types of pointers like
[]*mapor[]*[]string, which should be supported as well, I guess. It will take some time to finish the implementation, so I marked the PR as a draft (work in progress). I will let you know when it is finished.