Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion deepobject.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@ package runtime

import (
"bytes"
"encoding"
"encoding/json"
"errors"
"fmt"
Expand DownExpand Up@@ -55,8 +56,16 @@ func marshalDeepObject(in interface{}, path []string) ([]string, error) {
// into a deepObject style set of subscripts. [a, b, c] turns into
// [a][b][c]
prefix := "[" + strings.Join(path, "][") + "]"

var value string
if t == nil {
value = "null"
} else {
value = fmt.Sprintf("%v", t)
}

result = []string{
prefix + fmt.Sprintf("=%v", t),
prefix + fmt.Sprintf("=%s", value),
}
}
return result, nil
Expand DownExpand Up@@ -268,6 +277,7 @@ func assignPathValues(dst interface{}, pathValues fieldOrValue) error {
dst = reflect.Indirect(aPtr)
}
dst.Set(reflect.ValueOf(date))
return nil
}
if it.ConvertibleTo(reflect.TypeOf(time.Time{})) {
var tm time.Time
Expand All@@ -288,6 +298,13 @@ func assignPathValues(dst interface{}, pathValues fieldOrValue) error {
dst = reflect.Indirect(aPtr)
}
dst.Set(reflect.ValueOf(tm))
return nil
}
// For other struct types that implement TextUnmarshaler (e.g. uuid.UUID),
// use that for binding. This comes after the legacy Date/time.Time checks
// above which have special fallback format handling.
if tu, ok := v.Interface().(encoding.TextUnmarshaler); ok {
return tu.UnmarshalText([]byte(pathValues.value))
}
fieldMap, err := fieldIndicesByJSONTag(iv.Interface())
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions deepobject_test.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,6 +63,7 @@ func TestDeepObject(t *testing.T) {
om := map[string]int{
"additional": 1,
}

d := MockBinder{Time: time.Date(2020, 2, 1, 0, 0, 0, 0, time.UTC)}

two := 2
Expand Down
Loading