Closed cugu closed 6 months ago
Changing api.User
to *api.User
func TestUserMarshal(t *testing.T) {
- user := api.User{
+ user := &api.User{
Teams: nil,
}
solves the issue.
It seems like encoding/json
does not call MarshalJSON
on pointer receiver: https://go.dev/play/p/tmEeCUL_6NY
That works. Thanks!
What version of ogen are you using?
v1.2.0
Can this issue be reproduced with the latest version?
Yes
What did you do?
I have a server created by ogen, which serves user objects with an optional team field, that is a string array.
json.Marshal
this with teams set tonil
becomesnull
which I think is reasonable. Howeverjson.Unmarshal
fails and always expects an array.What did you expect to see?
Unmarshal without error
What did you see instead?
Unmarshal created an error: