diff --git a/encode.go b/encode.go index 45e8d1e..de9e72a 100644 --- a/encode.go +++ b/encode.go @@ -120,6 +120,11 @@ func (e *encoder) marshal(tag string, in reflect.Value) { e.nodev(in) return case Node: + if !in.CanAddr() { + var n = reflect.New(in.Type()).Elem() + n.Set(in) + in = n + } e.nodev(in.Addr()) return case time.Time: diff --git a/encode_test.go b/encode_test.go index 978d4d6..4a8bf2e 100644 --- a/encode_test.go +++ b/encode_test.go @@ -448,6 +448,14 @@ var marshalTests = []struct { }, }, "value: 'foo'\n", + }, { + yaml.Node{ + Kind: yaml.ScalarNode, + Tag: "!!str", + Value: "foo", + Style: yaml.SingleQuotedStyle, + }, + "'foo'\n", }, // Enforced tagging with shorthand notation (issue #616).