Open albttx opened 6 years ago
Not ideal, but you can work around this issue by pre-processing your struct using mapstructure with its nifty DecoderConfig.TagName
config option set to "json".
m := make(map[string]interface{})
config := &mapstructure.DecoderConfig{Result: &m, TagName: "json"}
if decoder, err := mapstructure.NewDecoder(config); err != nil {
return err
} else if err := decoder.Decode(v); err != nil {
return err
}
return yaml.Marshal(m)
I know you're not a fan @niemeyer but we really need some way to handle generated/external models (especially gRPC).
EDIT: mapstructure only processes the root object. For a full recursive solution you can use structs instead since it also supports a configurable tag name (ahem, very handy convention!).
s := structs.New(v)
s.TagName = "json"
return yaml.Marshal(s.Map())
from
encoding/json
package:I currently working with data structure generated with protocol-buffer and the struct have:
I know grpc handle write
json:"-"
and notyaml:"-"
, but i might be nice to consider handle it