diff --git a/pkg/printers/json.go b/pkg/printers/json.go index 0f3e880efe..da34153f51 100644 --- a/pkg/printers/json.go +++ b/pkg/printers/json.go @@ -27,7 +27,10 @@ func NewJSONPrinter() OutputPrinter { // the supplied writer. func (j *JSONPrinter) PrintObj(obj interface{}, writer io.Writer) error { if obj, ok := obj.(runtime.Object); ok { - return j.runtimePrinter.PrintObj(obj, writer) + if err := j.runtimePrinter.PrintObj(obj, writer); err == nil { + // if an error occurred, we may still be able to serialise using json package directly + return nil + } } b, err := json.MarshalIndent(obj, "", " ") diff --git a/pkg/printers/yaml.go b/pkg/printers/yaml.go index 5fcd984cbf..631ccc0297 100644 --- a/pkg/printers/yaml.go +++ b/pkg/printers/yaml.go @@ -26,7 +26,10 @@ func NewYAMLPrinter() OutputPrinter { // the supplied writer. func (y *YAMLPrinter) PrintObj(obj interface{}, writer io.Writer) error { if obj, ok := obj.(runtime.Object); ok { - return y.runtimePrinter.PrintObj(obj, writer) + if err := y.runtimePrinter.PrintObj(obj, writer); err == nil { + // if an error occurred, we may still be able to serialise using yaml package directly + return nil + } } b, err := yaml.Marshal(obj)