Closed
Description
Example code like this:
package main
import (
"encoding/json"
"fmt"
"github.com/json-iterator/go"
)
func main() {
type S1 struct {
F1 string `json:",omitempty"`
}
type S2 struct {
*S1
F2 string `json:",omitempty"`
}
s1 := &S1{
//F1: "abc",
}
s2 := &S2{
S1: s1,
F2: "123",
}
b, err := json.Marshal(s2)
if err != nil {
panic(err)
}
fmt.Println("Marshalled by json:", string(b))
b, err = jsoniter.Marshal(s2)
if err != nil {
panic(err)
}
fmt.Println("Marshalled by jsoniter:", string(b))
}
And the output is:
Marshalled by json: {"F2":"123"}
Marshalled by jsoniter: {"F1":"","F2":"123"}
Metadata
Metadata
Assignees
Labels
No labels