intridea/grape — pull request #273 by dnd (2012-11-10 18:01:32+00:00)
Title: Prefer custom #to_json implementations over #serializable_hash

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.