From a8ebc131de34b57f8df67dec66867552db2e1dea Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Tue, 29 Nov 2016 11:18:49 +0100 Subject: [PATCH] Workaround ugorji/go/codecs regression --- pkg/apis/meta/v1/types.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/pkg/apis/meta/v1/types.go b/pkg/apis/meta/v1/types.go index b7fb2cd37bf..66a166352d6 100644 --- a/pkg/apis/meta/v1/types.go +++ b/pkg/apis/meta/v1/types.go @@ -27,8 +27,9 @@ package v1 import ( "fmt" - "strings" + + "github.com/ugorji/go/codec" ) // TypeMeta describes an individual object in an API response or request @@ -422,6 +423,27 @@ func (vs Verbs) String() string { return fmt.Sprintf("%v", []string(vs)) } +// CodecEncodeSelf is part of the codec.Selfer interface. +func (vs *Verbs) CodecEncodeSelf(encoder *codec.Encoder) { + encoder.Encode(vs) +} + +// CodecDecodeSelf is part of the codec.Selfer interface. It is overwritten here to make sure +// that an empty verbs list is not decoded as nil. On the other hand, an undefined verbs list +// will lead to nil because this decoding for Verbs is not invoked. +// +// TODO(sttts): this is due to a ugorji regression: https://github.com/ugorji/go/issues/119. Remove the +// workaround when the regression is fixed. +func (vs *Verbs) CodecDecodeSelf(decoder *codec.Decoder) { + m := []string{} + decoder.Decode(&m) + if len(m) == 0 { + *vs = []string{} + } else { + *vs = m + } +} + // APIResourceList is a list of APIResource, it is used to expose the name of the // resources supported in a specific group and version, and if the resource // is namespaced.