I have a short and simple question, which I am currently unable to figure out using the documentation of the
I have a
struct which contains some keys with values of the
Decimal struct. I would like to have the
Decimal struct (I am using the Decimal Library for it) always converted to
float when encoding to JSON. So far I only know that I would have to implement the Json.Encoder protocol and have the
encode method to call
Decimal.to_float(value). But I am not sure how to do that? How do I implement the protocol?
I have tried to just make a file like this:
defimpl Jason.Encoder, for: Decimal do def encode(struct, opts) do Jason.Encode.map(Decimal.to_float(struct), opts) end end
However, this code never runs. Can anybod help?