@@ -56,8 +56,8 @@ func (e Element) StructField() (_ reflect.StructField, ok bool) {
5656
5757// MapAny maps any object (struct, map, slice etc.) by converting each struct found to a map.
5858//
59- // * for struct the returned type will be map[string]interface{}
60- // * for slice of structs the returned type will be []map[string]interface{}
59+ // - for struct the returned type will be map[string]interface{}
60+ // - for slice of structs the returned type will be []map[string]interface{}
6161func (i Mapper ) MapAny (v interface {}) (interface {}, error ) {
6262 return i .newInstance ().mapAny ("" , v )
6363}
@@ -198,10 +198,11 @@ func (i Mapper) mapElement(fieldPath string, element Element, result map[string]
198198}
199199
200200func (i Mapper ) mapSlice (path string , reflectValue reflect.Value ) (_ interface {}, err error ) {
201- kind := reflectValue .Type ().Elem ().Kind ()
201+ genericType := reflectValue .Type ().Elem ()
202+ kind := genericType .Kind ()
202203
203- switch kind {
204- case reflect .Struct :
204+ switch {
205+ case kind == reflect .Struct || ( kind == reflect . Ptr && genericType . Elem (). Kind () == reflect . Struct ) :
205206 shouldConvert , err := i .ShouldConvert (path , reflectValue )
206207 if err != nil {
207208 return nil , fmt .Errorf ("ShouldConvert failed: %w" , err )
@@ -221,8 +222,8 @@ func (i Mapper) mapSlice(path string, reflectValue reflect.Value) (_ interface{}
221222 }
222223
223224 return slice , nil
224- case reflect .Map :
225- if reflectValue . Type (). Elem () .Key ().Kind () != reflect .String {
225+ case kind == reflect .Map :
226+ if genericType .Key ().Kind () != reflect .String {
226227 return reflectValue .Interface (), nil
227228 }
228229
@@ -245,8 +246,8 @@ func (i Mapper) mapSlice(path string, reflectValue reflect.Value) (_ interface{}
245246 }
246247
247248 return slice , nil
248- case reflect .Slice :
249- sliceElem := reflectValue . Type (). Elem () .Elem ()
249+ case kind == reflect .Slice :
250+ sliceElem := genericType .Elem ()
250251
251252 if sliceElem .Kind () == reflect .Struct ||
252253 (sliceElem .Kind () == reflect .Map && sliceElem .Key ().Kind () == reflect .String ) {
0 commit comments