You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
561 B
Go
42 lines
561 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
|
|
jsonx "github.com/segmentio/encoding/json"
|
|
)
|
|
|
|
type A struct {
|
|
AA string `json:"aa,omitempty"`
|
|
}
|
|
|
|
type B struct {
|
|
*A
|
|
BB string `json:"bb,omitempty"`
|
|
}
|
|
|
|
func main() {
|
|
var b B
|
|
b.BB = "b"
|
|
b.A = new(A)
|
|
b.A.AA = ""
|
|
|
|
fmt.Println("github.com/segmentio/encoding/json")
|
|
data, err := jsonx.Marshal(b)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
fmt.Println(string(data))
|
|
fmt.Println()
|
|
|
|
fmt.Println("encoding/json")
|
|
data, err = json.Marshal(b)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
fmt.Println(string(data))
|
|
}
|