nathanl
Oban Met generating JSON encoding error: (Protocol.UndefinedError) protocol JSON.Encoder not implemented
I see this error locally when running my application. mix deps shows versions:
- oban 2.19.1
- oban_met 0.1.11
- oban_pro 1.5.0
- oban_web 2.10.2
- telemetry 1.3.0
- telemetry_metrics 1.1.0
- telemetry_poller 1.1.0
[error] GenServer {Oban.Registry, {Oban, Oban.Met.Listener}} terminating
** (Protocol.UndefinedError) protocol JSON.Encoder not implemented for type Oban.Met.Values.Gauge (a struct), the protocol must be explicitly implemented.
If you have a struct, you can derive the implementation specifying which fields should be encoded to JSON:
@derive {JSON.Encoder, only: [....]}
defstruct ...
It is also possible to encode all fields, although this should be used carefully to avoid accidentally leaking private information when new fields are added:
@derive JSON.Encoder
defstruct ...
Finally, if you don't own the struct you want to encode to JSON, you may use Protocol.derive/3 placed outside of any module:
Protocol.derive(JSON.Encoder, NameOfTheStruct, only: [...])
Protocol.derive(JSON.Encoder, NameOfTheStruct). This protocol is implemented for the following type(s): Atom, BitString, Date, DateTime, Decimal, Duration, Float, Integer, List, Map, NaiveDateTime, Oban.Pro.Producer, Oban.Pro.Producer.Meta.GlobalLimit, Oban.Pro.Producer.Meta.GlobalLimit.Partition, Oban.Pro.Producer.Meta.RateLimit, Oban.Pro.Producer.Meta.RateLimit.Partition, Time
Got value:
%Oban.Met.Values.Gauge{data: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}
(elixir 1.18.2) lib/json.ex:1: JSON.Encoder.impl_for!/1
(elixir 1.18.2) lib/json.ex:109: JSON.Encoder.encode/2
(elixir 1.18.2) src/elixir_json.erl:323: :elixir_json."-do_encode_map/2-lc$^0/1-0-"/2
(elixir 1.18.2) src/elixir_json.erl:323: :elixir_json.do_encode_map/2
(elixir 1.18.2) src/elixir_json.erl:308: :elixir_json.do_encode_list/2
(elixir 1.18.2) src/elixir_json.erl:323: :elixir_json."-do_encode_map/2-lc$^0/1-0-"/2
(elixir 1.18.2) src/elixir_json.erl:323: :elixir_json."-do_encode_map/2-lc$^0/1-0-"/2
(elixir 1.18.2) src/elixir_json.erl:323: :elixir_json.do_encode_map/2
(oban 2.19.1) lib/oban/notifier.ex:307: Oban.Notifier.encode/1
(elixir 1.18.2) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
(oban 2.19.1) lib/oban/notifier.ex:202: anonymous fn/4 in Oban.Notifier.notify/3
(telemetry 1.3.0) /Users/me/code/myapp/deps/telemetry/src/telemetry.erl:324: :telemetry.span/3
(oban_met 0.1.11) lib/oban/met/listener.ex:82: Oban.Met.Listener.handle_info/2
(stdlib 6.2) gen_server.erl:2345: :gen_server.try_handle_info/3
(stdlib 6.2) gen_server.erl:2433: :gen_server.handle_msg/6
(stdlib 6.2) proc_lib.erl:329: :proc_lib.init_p_do_apply/3
Last message: :report
Most Liked
sorentwo
Oban Core Team
Is there a workaround for this?
You can use oban_met v1.0 with override: true to force it. There aren’t any API changes between v0.1.11 and v1.0.0 and oban_web can use it just fine.
2
sorentwo
Oban Core Team
Oban added a transparent switch between Jason and JSON, which must also be respected by the other packages. In this case, oban_met is behind a version.
Upgrading oban_web (Changelog — Oban Web v2.12.5) and oban_met (Changelog — Oban Met v1.0.1) to the latest versions will fix the issue:
{:oban_web, "~> 2.11"},
{:oban_met, "~> 1.0"}
1
Popular in Questions
I have a super simple question about elixir - how would I take a file like this
foo
bar
baz
and output a new file that enumerates th...
New
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
I have VueJS GUIs with the project generated using Webpack.
I have Elixir modules that will need to be used by the VueJS GUIs.
I forese...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> somethi...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
can someone please explain to me how Enum.reduce works with maps
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
The documentation above suggests that while ...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
Other popular topics
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including.
What is Phoenix LiveV...
New
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode.
The solution seems to be, in a hyphena...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








