You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an inline field has both "inline" and "omitempty" tag, using Marshal will get an illegal json. The result is correct if the field only has a "inline" tag.
code example:
package main
import (
"encoding/json"
"fmt"
gojson "github.com/goccy/go-json"
)
type A struct {
Foo string `json:"foo"`
*B `json:",inline,omitempty"`
}
type B struct {
Bar string `json:"bar"`
}
func main() {
a := A{
Foo: "fff",
B: &B{
Bar: "bbb",
},
}
jsonBytes, _ := json.Marshal(a)
fmt.Println(string(jsonBytes)) // {"foo":"fff","bar":"bbb"}
gojsonBytes, _ := gojson.Marshal(a)
fmt.Println(string(gojsonBytes)) // {"foo":"fff","B":"bar":"bbb"}
}
The text was updated successfully, but these errors were encountered:
When an inline field has both "inline" and "omitempty" tag, using Marshal will get an illegal json. The result is correct if the field only has a "inline" tag.
code example:
The text was updated successfully, but these errors were encountered: