New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON encoding #46
Comments
You can use a JSON library for that, for example https://github.com/devinus/poison. |
Right but even then you have to the hardwork of re-encoding them yourself: devinus/poison#66 (comment). |
If you are using master of this library you can implement the protocol for ids: defimpl Poison.Encoder, for: BSON.ObjectId do
def encode(id), do: BSON.ObjectId.encode(id)
end |
Ah nice! Here's the implementation in case anyone else hits this: defimpl Poison.Encoder, for: BSON.ObjectId do
def encode(id, options) do
BSON.ObjectId.encode!(id) |> Poison.Encoder.encode(options)
end
end Thanks! |
Where do I add this code? When I try it in various places I always get:
I don't reference Poison.Encoder anywhere else. |
@beno Anywhere in your Elixir files under the |
But then I run into the above warning and the code indeed has no effect. |
If you get that warning you have some other issue with your project since you should not get it. If you have some way to share your project I can take a look at it. |
When I create a new mix app, with 2 dependencies (poison and mongoldb) and just the code above in lib I run into this issue. But interestingly only when I type I got confused here, because the initial compile also gives a warning:
So the code above is not valid out of the box. Can you please shed some light on this? |
The
|
I was on Elixir 1.3.1, have just now updated to Elixir 1.3.2 but the consolidated protocol warning remains. @ericmj here is a repo which produces the error https://github.com/beno/consolidate_error |
@beno Please open an issue on the Elixir project if the warning is still happening. |
Allright, done elixir-lang/elixir#5228 |
Would be useful to encode to JSON, e.g. map of strings:
I'm pretty new to Elixir and this is above my level still, but when I can do it I'll make a PR if there isn't already.
The text was updated successfully, but these errors were encountered: