Rename Object to EmbeddedObject

This commit is contained in:
Daniel Smith
2014-09-05 14:43:35 -07:00
parent e4cd06d2b9
commit 7790961011
9 changed files with 24 additions and 24 deletions

View File

@@ -26,7 +26,7 @@ import (
// embedded within other API types.
// UnmarshalJSON implements the json.Unmarshaler interface.
func (a *Object) UnmarshalJSON(b []byte) error {
func (a *EmbeddedObject) UnmarshalJSON(b []byte) error {
// Handle JSON's "null": Decode() doesn't expect it.
if len(b) == 4 && string(b) == "null" {
a.Object = nil
@@ -42,7 +42,7 @@ func (a *Object) UnmarshalJSON(b []byte) error {
}
// MarshalJSON implements the json.Marshaler interface.
func (a Object) MarshalJSON() ([]byte, error) {
func (a EmbeddedObject) MarshalJSON() ([]byte, error) {
if a.Object == nil {
// Encode unset/nil objects as JSON's "null".
return []byte("null"), nil
@@ -52,7 +52,7 @@ func (a Object) MarshalJSON() ([]byte, error) {
}
// SetYAML implements the yaml.Setter interface.
func (a *Object) SetYAML(tag string, value interface{}) bool {
func (a *EmbeddedObject) SetYAML(tag string, value interface{}) bool {
if value == nil {
a.Object = nil
return true
@@ -76,7 +76,7 @@ func (a *Object) SetYAML(tag string, value interface{}) bool {
}
// GetYAML implements the yaml.Getter interface.
func (a Object) GetYAML() (tag string, value interface{}) {
func (a EmbeddedObject) GetYAML() (tag string, value interface{}) {
if a.Object == nil {
value = "null"
return

View File

@@ -22,18 +22,18 @@ import (
"testing"
)
func TestObject(t *testing.T) {
func TestEmbeddedObject(t *testing.T) {
type EmbeddedTest struct {
JSONBase `yaml:",inline" json:",inline"`
Object Object `yaml:"object,omitempty" json:"object,omitempty"`
EmptyObject Object `yaml:"emptyObject,omitempty" json:"emptyObject,omitempty"`
Object EmbeddedObject `yaml:"object,omitempty" json:"object,omitempty"`
EmptyObject EmbeddedObject `yaml:"emptyObject,omitempty" json:"emptyObject,omitempty"`
}
AddKnownTypes("", EmbeddedTest{})
AddKnownTypes("v1beta1", EmbeddedTest{})
outer := &EmbeddedTest{
JSONBase: JSONBase{ID: "outer"},
Object: Object{
Object: EmbeddedObject{
&EmbeddedTest{
JSONBase: JSONBase{ID: "inner"},
},

View File

@@ -42,7 +42,7 @@ type JSONBase struct {
APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"`
}
// Object has appropriate encoder and decoder functions, such that on the wire, it's
// EmbeddedObject has appropriate encoder and decoder functions, such that on the wire, it's
// stored as a []byte, but in memory, the contained object is accessable as an interface{}
// via the Get() function. Only objects having a JSONBase may be stored via Object.
// The purpose of this is to allow an API object of type known only at runtime to be
@@ -52,7 +52,7 @@ type JSONBase struct {
//
// Note that objects will be serialized into the api package's default external versioned type;
// this should be fixed in the future to use the version of the current Codec instead.
type Object struct {
type EmbeddedObject struct {
Object interface{}
}