feat: Tesla.Middleware.JSON: Add support for Elixir 1.18's JSON module#747
Merged
yordis merged 4 commits intoelixir-tesla:masterfrom Feb 3, 2025
adamu:json
Merged
feat: Tesla.Middleware.JSON: Add support for Elixir 1.18's JSON module#747yordis merged 4 commits intoelixir-tesla:masterfrom adamu:json
yordis merged 4 commits intoelixir-tesla:masterfrom
adamu:json
Conversation
Member
|
🚀 💜 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a proposal for one way to add support to the built-in
JSONmodule available in Elixir 1.18.There were a few challenges with this, because Tesla makes assumptions about how an engine should behave that JSON doesn't conform to. To work around this I created a
JSONAdaptermodule that conforms to Tesla's expectations, and allows users to simply specifyfor common cases, which will give people an easy path to migrate away from
Jason, for example.Elixir's built-in JSON module also supports custom encoders and decoders, which could theoretically be supplied via this middlewear's
engine_optsparam. But considering that would require additional wrapper/adapter logic, and the same thing can be achieved using theencoder:anddecoder:options, I decided that might be overkill.Long term, I don't think the
:engineoption makes much sense, because there are too many assumptions involved without defining a proper behaviour. Perhaps deprecating it and focussing on the:encoderand:decoderoptions might make sense?Docs preview
Related issues
Tesla.Middleware.JSONengine toJSONmodule for Elixir 1.18 #743