poison
poison copied to clipboard
Bring back Phoenix compatibility
Hi! Dropping encode_to_iodata!/1
has lead to losing compatibility with Phoenix as can be seen with https://github.com/phoenixframework/phoenix/pull/4727. If this PR gets accepted it will unblock https://github.com/phoenixframework/phoenix/pull/4728 which brings that compatibility back.
PR's been open since Aug 2021 😭 https://github.com/devinus/poison/pull/197
Thanks, @RudolfMan! Well, I can only hope this PR is heard as another voice in the case 🤞
This is still a problem, but I'm cleaning up some of my repos, so I'll be closing this PR. If one needs to use Poison with Phoenix, Postgrex, or PhoenixSwagger, then a shim module like this one might be handy:
defmodule MyApp.Poison do
@moduledoc false
defdelegate decode(iodata, options \\ %{}), to: Poison
defdelegate decode!(value, options \\ %{}), to: Poison
defdelegate encode(value, options \\ %{}), to: Poison
defdelegate encode!(value, options \\ %{}), to: Poison
@doc """
Encodes a value to JSON, returning an iodata.
Equivalent to `encode!(value, iodata: true)`.
Prefer `encode!/1`.
This function only exists for compatibility with Phoenix, Postgres, or PhoenixSwagger.
"""
def encode_to_iodata!(value) do
Poison.encode!(value, iodata: true)
end
end
Then the only remaining bit is the config:
$ rg json_lib
config/config.exs
9:config :phoenix, :json_library, MyApp.Poison
10:config :postgrex, :json_library, MyApp.Poison
22:config :phoenix_swagger, json_library: MyApp.Poison