-
-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delegate to JSON and fallback to Jason
Adds a new `Oban.JSON` module that detects whether the new JSON module is available at compile time. If it isn't available, then it falls back to Jason, and if Jason isn't available (which is extremely rare) then it warns about a missing module. This approach was chosen over a config option for backward compatibility because Oban will only support the JSON module once the minimum supported Elixir version is v1.18. Closes #1213
- Loading branch information
Showing
8 changed files
with
41 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule Oban.JSON do | ||
@moduledoc false | ||
|
||
# Delegates to JSON in Elixir v1.18+ or Jason for earlier versions | ||
|
||
cond do | ||
Code.ensure_loaded?(JSON) -> | ||
defdelegate decode!(data), to: JSON | ||
defdelegate encode!(data), to: JSON | ||
defdelegate encode_to_iodata!(data), to: JSON | ||
|
||
Code.ensure_loaded?(Jason) -> | ||
defdelegate decode!(data), to: Jason | ||
defdelegate encode!(data), to: Jason | ||
defdelegate encode_to_iodata!(data), to: Jason | ||
|
||
true -> | ||
message = "Missing a compatible JSON library, add `:jason` to your deps." | ||
|
||
IO.warn(message, Macro.Env.stacktrace(__ENV__)) | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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