mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-25 10:18:59 +02:00
fix(serialization): improve nil handling in mapUnmarshalValidate
This commit is contained in:
@@ -189,15 +189,7 @@ func mapUnmarshalValidate(src SerializedObject, dst any, checkValidateTag bool)
|
|||||||
dstV := reflect.ValueOf(dst)
|
dstV := reflect.ValueOf(dst)
|
||||||
dstT := dstV.Type()
|
dstT := dstV.Type()
|
||||||
|
|
||||||
if src == nil {
|
if src != nil && dstT.Implements(mapUnmarshalerType) {
|
||||||
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) {
|
|
||||||
dstV, _, err = dive(dstV)
|
dstV, _, err = dive(dstV)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -210,6 +202,14 @@ func mapUnmarshalValidate(src SerializedObject, dst any, checkValidateTag bool)
|
|||||||
return err
|
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 data fields to lower no-snake
|
||||||
// convert target fields to lower no-snake
|
// convert target fields to lower no-snake
|
||||||
// then check if the field of data is in the target
|
// then check if the field of data is in the target
|
||||||
|
|||||||
Reference in New Issue
Block a user