Skip to content

Commit b9a5f66

Browse files
committed
allow 'json' option regardless of type
1 parent ff5bcf4 commit b9a5f66

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

query/encode.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,16 @@ func reflectValue(values url.Values, val reflect.Value, scope string) error {
195195
continue
196196
}
197197

198+
if opts.Contains("json") {
199+
var b []byte
200+
b, err := json.Marshal(sv.Interface())
201+
if err != nil {
202+
return err
203+
}
204+
values.Add(name, string(b))
205+
continue
206+
}
207+
198208
if sv.Type().Implements(encoderType) {
199209
// if sv is a nil pointer and the custom encoder is defined on a non-pointer
200210
// method receiver, set sv to the zero value of the underlying type
@@ -261,18 +271,8 @@ func reflectValue(values url.Values, val reflect.Value, scope string) error {
261271
}
262272

263273
if sv.Kind() == reflect.Struct {
264-
if opts.Contains("json") {
265-
var b []byte
266-
b, err := json.Marshal(sv.Interface())
267-
if err != nil {
268-
return err
269-
}
270-
271-
values.Add(name, valueString(reflect.ValueOf(string(b)), opts, sf))
272-
} else {
273-
if err := reflectValue(values, sv, name); err != nil {
274-
return err
275-
}
274+
if err := reflectValue(values, sv, name); err != nil {
275+
return err
276276
}
277277
continue
278278
}

0 commit comments

Comments
 (0)