Merge pull request #40 from gocontrib/fix-time-nesting

fix nesting of time fields
This commit is contained in:
Fatih Arslan 2015-11-26 12:33:33 +02:00
commit 9a7733345f
2 changed files with 20 additions and 1 deletions

View File

@ -94,7 +94,12 @@ func (s *Struct) Map() map[string]interface{} {
// map[string]interface{} too
n := New(val.Interface())
n.TagName = s.TagName
finalVal = n.Map()
m := n.Map()
if len(m) == 0 {
finalVal = val.Interface()
} else {
finalVal = m
}
} else {
finalVal = val.Interface()
}

View File

@ -296,6 +296,20 @@ func TestMap_Anonymous(t *testing.T) {
}
}
func TestMap_TimeField(t *testing.T) {
type A struct {
CreatedAt time.Time
}
a := &A{CreatedAt: time.Now().UTC()}
m := Map(a)
_, ok := m["CreatedAt"].(time.Time)
if !ok {
t.Error("Time field must be final")
}
}
func TestStruct(t *testing.T) {
var T = struct{}{}