I have an simple application that needs to do some JSON encoding from a MongoDB datastore. However, when I add the code below, I get this warning and the code never :
defimpl Poison.Encoder, for: BSON.ObjectId do
def encode(id, options) do
BSON.ObjectId.encode!(id) |> Poison.Encoder.encode(options)
end
end
warning: the Poison.Encoder protocol has already been consolidated, an implementation for BSON.ObjectId has no effect
I don’t reference Poison.Encoder anywhere else in my code, but the warning is legit and indeed the code has no effect. I have two questions: what does the warning mean and how to prevent it.
You are consolidating the protocol at the wrong time. Where are you placing the code snippet above? Is it inside a function? In your test_helper.exs? Your protocol implementations must be the root of your files, usually not nested.
Hmm, interesting, this only happens when I type recompile at the iex prompt. A full quit/start cycle of iex doesn’t seem to have the problem. I guess the two are not equivalent?