Workaround ugorji/go/codecs regression

pull/6/head
Dr. Stefan Schimanski 2016-11-29 11:18:49 +01:00 committed by Dr. Stefan Schimanski
parent 0301487de0
commit a8ebc131de
1 changed files with 23 additions and 1 deletions

View File

@ -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.