From 190d5e1ece15c65f19fe58c4a81ab7896fa786b8 Mon Sep 17 00:00:00 2001 From: yusing Date: Sat, 13 Sep 2025 23:20:10 +0800 Subject: [PATCH] fix(serialization): improve nil handling in mapUnmarshalValidate --- internal/serialization/serialization.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/serialization/serialization.go b/internal/serialization/serialization.go index 4efe4e7f..2464d014 100644 --- a/internal/serialization/serialization.go +++ b/internal/serialization/serialization.go @@ -189,15 +189,7 @@ func mapUnmarshalValidate(src SerializedObject, dst any, checkValidateTag bool) dstV := reflect.ValueOf(dst) dstT := dstV.Type() - if src == nil { - if dstV.CanSet() { - dstV.Set(reflect.Zero(dstT)) - return nil - } - return gperr.Errorf("deserialize: src is %w and dst is not settable", ErrNilValue) - } - - if dstT.Implements(mapUnmarshalerType) { + if src != nil && dstT.Implements(mapUnmarshalerType) { dstV, _, err = dive(dstV) if err != nil { return err @@ -210,6 +202,14 @@ func mapUnmarshalValidate(src SerializedObject, dst any, checkValidateTag bool) return err } + if src == nil { + if dstV.CanSet() { + dstV.Set(reflect.Zero(dstT)) + return nil + } + return gperr.Errorf("deserialize: src is %w and dst is not settable", ErrNilValue) + } + // convert data fields to lower no-snake // convert target fields to lower no-snake // then check if the field of data is in the target