0
0

Merge branch 'StreamBoat-fix_ptr_handling'

This commit is contained in:
Marty Schoch 2015-01-16 17:49:37 -05:00
commit 3e72949563
2 changed files with 34 additions and 1 deletions

View File

@ -254,7 +254,7 @@ func (dm *DocumentMapping) walkDocument(data interface{}, path []string, indexes
case reflect.Ptr:
ptrElem := val.Elem()
if ptrElem.IsValid() && ptrElem.CanInterface() {
dm.walkDocument(ptrElem.Interface(), path, indexes, context)
dm.processProperty(ptrElem.Interface(), path, indexes, context)
}
}
}

View File

@ -150,3 +150,36 @@ func TestMappingStructWithJSONTagsOneDisabled(t *testing.T) {
t.Errorf("expected to find 2 find, found %d", count)
}
}
func TestMappingStructWithPointerToString(t *testing.T) {
mapping := buildMapping()
name := "marty"
x := struct {
Name *string
}{
Name: &name,
}
doc := document.NewDocument("1")
err := mapping.mapDocument(doc, x)
if err != nil {
t.Fatal(err)
}
found := false
count := 0
for _, f := range doc.Fields {
if f.Name() == "Name" {
found = true
}
count++
}
if !found {
t.Errorf("expected to find field named 'Name'")
}
if count != 1 {
t.Errorf("expected to find 1 find, found %d", count)
}
}