-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Allow for custom JSON encoding implementations #1880
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1880 +/- ##
==========================================
+ Coverage 90.21% 90.97% +0.75%
==========================================
Files 31 32 +1
Lines 2770 2791 +21
==========================================
+ Hits 2499 2539 +40
+ Misses 173 161 -12
+ Partials 98 91 -7
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This will go in next minor v4.4 release. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM too!
@hoshsadiq Nice work! Could you also add a PR in github.com/labstack/echox to update the docs. I'd love to see an example using Jsoniter there. This PR is currently about JSON encoding only. Should we consider decoding JSON too? |
Will raise the PR in echox soon. I was thinking about the decoder, I just couldn't think where it would be needed. Not sure why. But now it makes sense. I'll update the PR soon. |
I've just pushed a new commit that also adds the decoder. Wasn't quite sure what to name the interface, so if you have a better name for it, feel free to suggest! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I'd like to take the chance to discuss on naming of the interface, as the name should not change anytime soon after that (and will stick probably with v5 too). I personally like Some other suggestions:
Other suggestions welcome, your feedback even more. |
Personally I like |
In my case I prefer an explicit name, even if it is longer, like io.ReadWriteCloser because it is self explanatory. So, for me, I prefer JSONEncodeDecoder |
That would lead to JSONWriter and JSONReader being to separate interfaces with a JSONReadWriter combining them. (That is no real objection, more a note of slight distaste for too long interface names) |
ping, I vote for |
I change my vote also to JSONSerializer, lets merge! ;-) |
well well well. I was about to rename it myself and push changes but I started to look at that interface and JSONCoder interface {
Encode(c Context, i interface{}, indent string) error
Decode(c Context, i interface{}) error
} |
Sorry, haven't had a chance to do this. If it becomes |
Makes sense 👍 . @hoshsadiq you want to do renaming part yourself or I'll do it - that PR is already open at my IDE. |
If you've got time feel free to do it, if not, I'll probably get to it on Sunday. |
done. I'll merge it and in couple of days prepare changelog and release in |
This PR is an alternative implementation to #1774.
It allows users to give a custom JSON encoder implementation including jsoniter as has been requested multiple times. My use-case is slightly different, in that I wanted to use https://github.com/google/jsonapi as the default JSON implementation.
Happy to try and raise some examples in the cookbook for this if this gets approved/merged.
closes #1177
closes #1204
closes #1394
closes #1698
closes #1774