michalmuskala / jason

A blazing fast JSON parser and generator in pure Elixir.
Other
1.6k stars 170 forks source link

At least please include a "List of Most Common custom Jason.Encoder" for people can share it #125

Closed haskric closed 3 years ago

haskric commented 3 years ago

I have include a simple defimpl for BSON.ObjectId of :mongodb library with the target of encode the json. Now, phoenix is using Jason by default then when people include mongodb, and try cast to Json, by default will found an error. "Jason.Encoder not implemented for #BSON.ObjectId<....>" I would like avoid this error.

I think that you prefer don´t add in Jason the implementations of protocol, I respect your decision, but I would like that you consider or think at least include a List of Most Common custom Jason.Encoder, for the people can share more easy. Only add in docs can improve the productivity.

Sorry all and Thanks,

michalmuskala commented 3 years ago

I believe a proper way to provide those would be to define integration packages e.g. jason_mongodb that defines appropriate protocols. This way it can be easily re-used and shared in the community, while not requiring me to maintain it in jason itself.

I'd be happy to keep a list of such packages in the documentation.

haskric commented 3 years ago

First of all, thanks for your time...

I am agree with you it´s better don´t add in jason library the protocol implementations of others libraries... then you suggest that each library build an independent package for implement the protocols to use jason... I wonder, what do you think about? use a package eg. jason_extension, jason_community... where the community can include the implementations of others libraries, or utils things for extension jason library without change the core... of course maybe it isnt the most efficient way because can include multiples things... but this it would let extension jason by the community and let you mantain jason core clean...

I haven’t packages, but I undestand than this packages that would need depends at least of jason for can use defimpl, because in other case the compilation throw error (** (ArgumentError) Jason.Encoder is not available...) but although I didn’t received compilation error about BSON.ObjectId when I was trying "defimpl Jason.Encoder, for: BSON.ObjectId do" into Jason... then yesterday I said the error of Elixir CI to 1.11x in the pull... I have the doubt if it´s require include the mongo deps, or it´s only a warning of dialyxir and if we are less strict can omitted the use of --warnings-as-errors. Maybe the prover way it’s that the package of eg. jason_mongo use Jason, mongodb deps… but I don’t know if it´s can cause problems…

My intention with this main suggest… it´s avoid the people found errors and they will need that add custom code in each project… it was the main reason of that I tried collaborated, but you are right and I am agree with your philosophy of maintain clear the Jason library.

I close the pull…

Thanks for your work…
Greetings from Spain ;)