-
-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: struct with map (the only one field) encoded to null
#376
Comments
trim21
changed the title
Struct with map encoded to
Bug: struct with map encoded to Jul 2, 2022
null
null
trim21
changed the title
Bug: struct with map encoded to
Bug: struct with map (only field) encoded to Jul 2, 2022
null
null
trim21
changed the title
Bug: struct with map (only field) encoded to
Bug: struct with map (the only one field) encoded to Jul 2, 2022
null
null
what is your expectation? I could not reproduce this problem in v0.9.8. func TestIssue376(t *testing.T) {
type Container struct {
V any `json:"value"`
}
type MapOnly struct {
b bool
Map map[string]int64 `json:"map"`
}
b, err := json.Marshal(Container{MapOnly{}})
if err != nil {
t.Fatal(err)
}
got := string(b)
expected := `{"value":{"map":null}}`
if got != expected {
t.Errorf("unexpected result: %v != %v", got, expected)
}
} what version did you use? |
Oh, sorry, I'm using 0.9.7. This bug behavior differently in 0.9.8, try this: (remove package main
import (
"fmt"
"github.com/goccy/go-json"
)
func main() {
type Container struct {
V any `json:"value"`
}
type MapOnly struct {
Map map[string]int64 `json:"map"`
}
b, err := json.Marshal(Container{MapOnly{}})
if err != nil {
panic(err)
}
fmt.Println(string(b))
} |
@orisano can you re-produce with new example? I just try this on master branch and it fail. func TestIssue376(t *testing.T) {
type Container struct {
V interface{} `json:"value"`
}
type MapOnly struct {
Map map[string]int64 `json:"map"`
}
b, err := json.Marshal(Container{MapOnly{}})
if err != nil {
t.Fatal(err)
}
got := string(b)
expected := `{"value":{"map":null}}`
if got != expected {
t.Errorf("unexpected result: %v != %v", got, expected)
}
} |
thanks, I reproduced. |
orisano
added a commit
to orisano/go-json
that referenced
this issue
Jul 2, 2022
goccy
added a commit
that referenced
this issue
Jul 4, 2022
Fix encoding of directed interface with typed nil
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output:
{"value":null}
The text was updated successfully, but these errors were encountered: