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

easyjson pollute standard json lib #239

Closed
zhangruiskyline opened this issue Jun 26, 2019 · 3 comments
Closed

easyjson pollute standard json lib #239

zhangruiskyline opened this issue Jun 26, 2019 · 3 comments
Labels

Comments

@zhangruiskyline
Copy link

Hi, It seems if I have used easyjson to generate some parsing file, and in code use

easyjson.Unmarshal(body, &mystruct)

it will parse uses easyjson. however, if I want to fall back into

json.Unmarshal(body, &mystruct)

it still uses easyjson parser, not standard json parser. since it will have same issue as easy JSON(case sensitive issue raised in #237)

is there sth wrong

@zhangruiskyline
Copy link
Author

just found out I need to explicitly NOT to put //easyjson:json for data structure, and do not use -all in easyjson generation, then it can fall back to default JSON, still wondering, can we just use easyjson or json to process with different lib?

@rvasily
Copy link
Contributor

rvasily commented Jun 26, 2019

easyjson generates (un)marshaling functions, so struct implements https://golang.org/pkg/encoding/json/#Unmarshaler interfaces, so we will have full drop-in replacement. You dont need to write easyjson.Unmarshal anywhere, generated code will be called from json.Unmarshal

This is a feature.

@zhangruiskyline
Copy link
Author

Thanks, @rvasily , I am confused about "You dont need to write easyjson.Unmarshal"

in easyJSON doc,

"easyjson also generates MarshalJSON and UnmarshalJSON funcs for Go struct types compatible with the standard json.Marshaler and json.Unmarshaler interfaces. Please be aware that using the standard json.Marshal / json.Unmarshal for marshaling/unmarshaling will incur a significant performance penalty when compared to using easyjson.Marshal / easyjson.Unmarshal."

so if we do not change code from json.Unmarshaler to easyjson.Unmarshal, do we have same performance as default JSON? as I have benchmarked , json.Unmarshaler is much slower

so I think in our code, we still need to change json.Unmarshaler to easyjson.Unmarshal? or even json.Unmarshaler will have same performance as easyjson.Unmarshal?

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

No branches or pull requests

2 participants