[go-experimental] Fix marshalling of of go oneOf structures to work on non-pointer receivers (#6314)

This commit is contained in:
Slavek Kabrda
2020-05-21 15:02:21 +02:00
committed by GitHub
parent c49d8fda8e
commit cac4170c0f
4 changed files with 12 additions and 12 deletions

View File

@@ -13,7 +13,7 @@ func {{{.}}}As{{classname}}(v *{{{.}}}) {{classname}} {
{{/oneOf}}
// Unmarshl JSON data into one of the pointers in the struct
// Unmarshal JSON data into one of the pointers in the struct
func (dst *{{classname}}) UnmarshalJSON(data []byte) error {
var err error
match := 0
@@ -53,8 +53,8 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error {
}
}
// Marshl data from the first non-nil pointers in the struct to JSON
func (src *{{classname}}) MarshalJSON() ([]byte, error) {
// Marshal data from the first non-nil pointers in the struct to JSON
func (src {{classname}}) MarshalJSON() ([]byte, error) {
{{#oneOf}}
if src.{{{.}}} != nil {
return json.Marshal(&src.{{{.}}})

View File

@@ -31,7 +31,7 @@ func BananaAsFruit(v *Banana) Fruit {
}
// Unmarshl JSON data into one of the pointers in the struct
// Unmarshal JSON data into one of the pointers in the struct
func (dst *Fruit) UnmarshalJSON(data []byte) error {
var err error
match := 0
@@ -74,8 +74,8 @@ func (dst *Fruit) UnmarshalJSON(data []byte) error {
}
}
// Marshl data from the first non-nil pointers in the struct to JSON
func (src *Fruit) MarshalJSON() ([]byte, error) {
// Marshal data from the first non-nil pointers in the struct to JSON
func (src Fruit) MarshalJSON() ([]byte, error) {
if src.Apple != nil {
return json.Marshal(&src.Apple)
}

View File

@@ -31,7 +31,7 @@ func BananaReqAsFruitReq(v *BananaReq) FruitReq {
}
// Unmarshl JSON data into one of the pointers in the struct
// Unmarshal JSON data into one of the pointers in the struct
func (dst *FruitReq) UnmarshalJSON(data []byte) error {
var err error
match := 0
@@ -74,8 +74,8 @@ func (dst *FruitReq) UnmarshalJSON(data []byte) error {
}
}
// Marshl data from the first non-nil pointers in the struct to JSON
func (src *FruitReq) MarshalJSON() ([]byte, error) {
// Marshal data from the first non-nil pointers in the struct to JSON
func (src FruitReq) MarshalJSON() ([]byte, error) {
if src.AppleReq != nil {
return json.Marshal(&src.AppleReq)
}

View File

@@ -31,7 +31,7 @@ func ZebraAsMammal(v *Zebra) Mammal {
}
// Unmarshl JSON data into one of the pointers in the struct
// Unmarshal JSON data into one of the pointers in the struct
func (dst *Mammal) UnmarshalJSON(data []byte) error {
var err error
match := 0
@@ -74,8 +74,8 @@ func (dst *Mammal) UnmarshalJSON(data []byte) error {
}
}
// Marshl data from the first non-nil pointers in the struct to JSON
func (src *Mammal) MarshalJSON() ([]byte, error) {
// Marshal data from the first non-nil pointers in the struct to JSON
func (src Mammal) MarshalJSON() ([]byte, error) {
if src.Whale != nil {
return json.Marshal(&src.Whale)
}