Allow for custom JSON encoding implementations#1880
Allow for custom JSON encoding implementations#1880aldas merged 3 commits intolabstack:masterfrom hoshsadiq:custom-json
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.
|
|
This will go in next minor v4.4 release. |
|
@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! |
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