Merge rogpeppe's branch '001-allow-nil-marshal'.
@@ -58,6 +58,10 @@ func (e *encoder) must(ok bool) {
}
func (e *encoder) marshal(tag string, in reflect.Value) {
+ if !in.IsValid() {
+ e.nilv()
+ return
+ }
if m, ok := in.Interface().(Marshaler); ok {
v, err := m.MarshalYAML()
if err != nil {
@@ -2,12 +2,13 @@ package yaml_test
import (
"fmt"
- . "gopkg.in/check.v1"
- "gopkg.in/yaml.v2"
"math"
"strconv"
"strings"
"time"
+
+ . "gopkg.in/check.v1"
+ "gopkg.in/yaml.v2"
)
var marshalIntTest = 123
@@ -17,6 +18,9 @@ var marshalTests = []struct {
data string
}{
{
+ nil,
+ "null\n",
+ }, {
&struct{}{},
"{}\n",
}, {