From 6d7edb1479cb5c7ae63096ab8d1b1de10a2f0844 Mon Sep 17 00:00:00 2001 From: John Guo Date: Thu, 13 Jul 2023 21:15:07 +0800 Subject: [PATCH] fix issue #2760 (#2763) --- util/gconv/gconv_map.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/util/gconv/gconv_map.go b/util/gconv/gconv_map.go index d51583350..9b169f39f 100644 --- a/util/gconv/gconv_map.go +++ b/util/gconv/gconv_map.go @@ -255,10 +255,21 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in dataMap = make(map[string]interface{}) ) for _, k := range mapKeys { + var ( + mapKeyValue = reflectValue.MapIndex(k) + mapValue interface{} + ) + if mapKeyValue.IsZero() { + // in case of: + // exception recovered: reflect: call of reflect.Value.Interface on zero Value + mapValue = reflect.New(mapKeyValue.Type()).Elem() + } else { + mapValue = mapKeyValue.Interface() + } dataMap[String(k.Interface())] = doMapConvertForMapOrStructValue( doMapConvertForMapOrStructValueInput{ IsRoot: false, - Value: reflectValue.MapIndex(k).Interface(), + Value: mapValue, RecursiveType: in.RecursiveType, RecursiveOption: in.RecursiveType == recursiveTypeTrue, Tags: in.Tags,