unmarshal: make copy of non addressable values (#576)

When unmarshaling into a nested struct in a map, the value is not
addressable. In that case, make a copy of it and modify it instead.

Fixes #575
This commit is contained in:
Thomas Pelletier
2021-08-31 20:22:38 -04:00
committed by GitHub
parent 69ab7e10d1
commit 1230ca485e
2 changed files with 60 additions and 0 deletions
+6
View File
@@ -408,6 +408,12 @@ func (d *decoder) handleKeyPart(key ast.Iterator, v reflect.Value, nextFn handle
mv = makeFn()
}
set = true
} else if !mv.CanAddr() {
t := v.Type().Elem()
oldmv := mv
mv = reflect.New(t).Elem()
mv.Set(oldmv)
set = true
}
x, err := nextFn(key, mv)