When serializing msgpack, only consider codec tag

When serializing structs with msgpack, only consider type tags of
`codec`.

Hashicorp/go-msgpack (based on ugorji/go) defaults to interpretting
`codec` tag if it's available, but falls to using `json` if `codec`
isn't present.

This behavior is surprising in cases where we want to serialize json
differently from msgpack, e.g. serializing `ConsulExposeConfig`.
This commit is contained in:
Mahmood Ali
2020-05-11 14:14:10 -04:00
parent 4d271ce595
commit 88808b2d30
4 changed files with 9 additions and 1 deletions

View File

@@ -65,6 +65,10 @@ var MsgpackHandle = func() *codec.MsgpackHandle {
h.BasicHandle.TimeNotBuiltin = true
h.MapType = reflect.TypeOf(map[string]interface{}(nil))
// only review struct codec tags - ignore `json` flags
h.TypeInfos = codec.NewTypeInfos([]string{"codec"})
return h
}()