From 2950dca3ce8d66c3e5b5440897a30bd3e776bfef Mon Sep 17 00:00:00 2001 From: Pavel Zarubin Date: Sun, 27 Mar 2022 03:40:46 +0300 Subject: [PATCH] Fix form mapping nullable types --- binding/form_mapping.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/binding/form_mapping.go b/binding/form_mapping.go index c24dd553..f0394dd9 100644 --- a/binding/form_mapping.go +++ b/binding/form_mapping.go @@ -236,7 +236,20 @@ func setWithProperType(val string, value reflect.Value, field reflect.StructFiel case time.Time: return setTimeField(val, field, value) } - return json.Unmarshal(bytesconv.StringToBytes(val), value.Addr().Interface()) + + err := json.Unmarshal(bytesconv.StringToBytes(val), value.Addr().Interface()) + + if err == nil { + return err + } + + ms, err := json.Marshal(val) + + if err != nil { + return err + } + + return json.Unmarshal(ms, value.Addr().Interface()) case reflect.Map: return json.Unmarshal(bytesconv.StringToBytes(val), value.Addr().Interface()) default: