Skip to content
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: incompatibility with standard lib #680

Open
bfreis opened this issue Jul 8, 2023 · 0 comments
Open

Bug: incompatibility with standard lib #680

bfreis opened this issue Jul 8, 2023 · 0 comments

Comments

@bfreis
Copy link

bfreis commented Jul 8, 2023

According to the docs, it's possible to get 100% compatibility with the standard lib:

100% compatibility with standard lib

Replace

import "encoding/json"
json.Marshal(&data)

with

import jsoniter "github.com/json-iterator/go"

var json = jsoniter.ConfigCompatibleWithStandardLibrary
json.Marshal(&data)

I found a case in which this doesn't happen: https://go.dev/play/p/fSAa6wRtDKA

The key piece of the above playground is that, if a struct type has a method MarshalJSON with a pointer receiver, and if there's a field of of a struct with the non-pointer type, the behavior diverge: the stdlib's encoding/json doesn't call MarshalJSON, but Jsoniter does. In the playground linked above, this is shown on the serialization of the field BarNoPtr.

Now, I'm not claiming that Jsoniter's behavior is incorrect (I think it's reasonable behavior; in the very least, it's much more consistent than stdlib's behavior, as the full playground shows). The issue I'm bringing up is specifically the claim of 100% compatibility when using jsoniter.ConfigCompatibleWithStandardLibrary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant