Skip to content

feat: Tesla.Middleware.JSON: Add support for Elixir 1.18's JSON module#747

Merged
yordis merged 4 commits intoelixir-tesla:masterfrom
adamu:json
Feb 3, 2025
Merged

feat: Tesla.Middleware.JSON: Add support for Elixir 1.18's JSON module#747
yordis merged 4 commits intoelixir-tesla:masterfrom
adamu:json

Conversation

@adamu
Copy link
Copy Markdown
Contributor

@adamu adamu commented Jan 26, 2025

This is a proposal for one way to add support to the built-in JSON module 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 JSONAdapter module that conforms to Tesla's expectations, and allows users to simply specify

engine: JSON

for 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_opts param. But considering that would require additional wrapper/adapter logic, and the same thing can be achieved using the encoder: and decoder: options, I decided that might be overkill.

Long term, I don't think the :engine option makes much sense, because there are too many assumptions involved without defining a proper behaviour. Perhaps deprecating it and focussing on the :encoder and :decoder options might make sense?

Docs preview

image

Related issues

@yordis yordis changed the title Tesla.Middleware.JSON: Add support for Elixir 1.18's JSON module feat: Tesla.Middleware.JSON: Add support for Elixir 1.18's JSON module Feb 3, 2025
@yordis yordis merged commit 1413167 into elixir-tesla:master Feb 3, 2025
@yordis
Copy link
Copy Markdown
Member

yordis commented Feb 3, 2025

🚀 💜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants