-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
(c *Ctx) JSON(data interface{}) error does not respect standard json annotations ( omitempty, inline) in nested structs #1549
Comments
Hi, I think Because, I'm wrong ? 🤔 |
Hi, It is a part of the spec https://pkg.go.dev/encoding/json#Marshal |
Hi, I just tried your code and it gives your expected response. Am I missing something?
|
Thank you you are right! Bug reproduced in nested structs only. |
internal encoding/json needs to be updated |
Hello @ReneWerner87, I've done some troubleshooting on this issue. When using nested struct with pointer type, the pointer is a wild pointer due to some incorrect code, so fiber/internal/encoding/json/encode.go Lines 769 to 771 in 89b85c2
I noticed that upstream https://github.com/segmentio/encoding also has this problem, can I migrate it to https://github.com/json-iterator/go via PR? |
I think using https://github.com/goccy/go-json or https://github.com/json-iterator/go good idea. We can do benchmark to compare performance. |
Looks like it's related to this |
you are welcome to test other json libraries, if the benchmarks look good, we can also switch to them after the benchmarks, of course, we need to shed some light on how trustworthy the source is |
Benchmark results: https://termbin.com/j4j19 Also, go-json seems has good compatibility with encoding/json stds. |
ok thx, would be cool if someone can provide a pull request for it, please in the way the other library was already added, so a copy with comments and without the unittests of the library itself, as these were already checked in main repository maybe you have to search the readme's if there is something to change here |
What should do we iso8601 and ascii dirs? Should we change json dir only? |
Fiber version
v2.19.0
Issue description
context Json method ignores annotation hints like
json:"token,omitempty"
,json:",inline"
in nested structsCode snippet
Bug
code snipped returns json:
Expected:
The text was updated successfully, but these errors were encountered: