MarshalYAML doesn't call MarshalYAML on returned value #134

Open
rogpeppe opened this Issue Oct 16, 2015 · 4 comments

Comments

Projects
None yet
4 participants
Contributor

rogpeppe commented Oct 16, 2015

From reading the docs, I'd expect the following example to print "something",
but it prints "y": 99 instead.

package main

import (
    "fmt"
    "log"
    "gopkg.in/yaml.v2"
)

func main() {
    t := T{99}
    data, err := yaml.Marshal(t)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("%s\n", data)
}

type T struct {
    X int
}

func (t T) MarshalYAML() (interface{}, error) {
    return S{t.X}, nil
}

type S struct {
    Y int
}

func (s S) MarshalYAML() (interface{}, error) {
    return "something", nil
}
Contributor

niemeyer commented Oct 16, 2015

Interested in offering a patch for this?

I am interested in getting this fixed too. +1

Contributor

rogpeppe commented Nov 13, 2015

I'd love to do a patch but there are at least 10 things that I need to do more than this that I know no-one else is ever going to do... Perhaps on a flight sometime, unless I find this bug blocking some other task.

Why MarshalYAML method of Marshaler interface returns interface{} rather than []byte like in encoding/json ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment