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)
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.