-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Prefer custom #to_json implementations over #serializable_hash #273
Conversation
Thanks. I am going to leave this open for comments :) |
As mentioned in this PR the implementation is a bit scary. Anyone please suggest something better? Maybe we can get away from guessing whether to call |
This definitely seems a bit too specific and scary to me. Maybe a better way would be to have an optional flag on the object, e.g. |
Maybe a different question would be, what is the purpose or reason for calling |
@dnd is right, of course. Want to try killing |
All that breaks are the three specs that specifically test for the serialization of an object implementing
Unfortunately this doesn't tell us at all why |
I am going to close this in favor of #282. Appreciate everybody's patience. |
As discussed on the mailing list, this is the change for json formatting to prefer #to_json over #serializable_hash when a custom implementation is found.
I had mentioned on the mailing list that a comparison to Object looked to be all that was needed. It turns out, however, that it's a bit muddier than that. Object was appearing as the method owner due to the object I was using being a Mongoid document.
The solution that worked ended up being a regex comparison for the owner matching
/^JSON::Ext::Generator::GeneratorMethods/
as there are multiple GeneratorMethods(Object, Array, Hash, etc...). It feels dirty, but I can't come up with a better solution at the moment.I could possibly change it to just check for the presence of more than one ancestor as well, but I'm not entirely sure how foolproof that is.