-
-
Notifications
You must be signed in to change notification settings - Fork 252
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
Issues with DelegateClass. #919
Comments
Can you provide more information about what you are looking for. I got the basics but am not sure if the app is a rails app or something else. Also, what is the preferred mode? It sounds like you are not using rails or else the :compat time format would be okay. If you can use some other mode that does not try to be compatible with the JSON gem there are a few more options to deal with a custom delegate marshalling. |
Sure! Yes, it's not a rails app, we use plain Ruby, with a routing microframework called Cuba. The mode we are currently using is Based on that, it would probably be allright to use a mode that doesn't try to be JSON gem compatible. |
Would it be possible to monkey-patch SimpleDelegate to add a |
Yes, we have currently a patch based on that idea, but we where looking for cleaner alternatives. The def to_hash
__getobj__
end and with the option But we have some concerns with this approach. The first one is conceptual, those delegate inner objects are not necessarily a This would be fixed by patching
|
I would advise against just returning |
Yea, that's exactly it. I did not follow you on the bit about the parallel class inheritance, but looking at the code and if you were open to make modifications to Oj to address this issue, I was thinking about an option that when set checks for |
If every call to dump an object had to check for whether the instance was a type of delegate that would be expensive. If a more generic solution was offered it would be worse. I do not want to make a special case for Delegates but a low performance overhead option might be to provide a hook that is called for each object. If the developer was willing to sacrifice performance they could define hook for what ever classes they wanted. |
Yes, that makes sense. The check would have been behind the option, so the cost of it would only have been payed by those interested in this behaviour. But I can see how a hook to modify the object can be a more generic solution for these issue. Although, now that I think about it, this can be done outside of Oj as well, like before serialization you could ask if the object is a delegate and in that case serialize the internal object instead of the delegate. |
It could be done outside Oj but the before hook/code would have to be able to traverse all object attributes to look for delegates and then create a duplicate tree of objects. It will be expensive unless you have a very specific case where delegates are alway top level objects. |
Yea you are right, for our current use case we only need to check the top level object, but that won't help for a general solution. Would you be open to a PR submission exploring the hooks idea from where we could iterate a solution? |
As long as it covers the general case, that would be great as long as you don't mind me being a bit picky. |
We started using
DelegateClass
on our codebase recently, and are experiencing some compatibility issues with Oj.The main problem has already been reported here #477, but the proposed solution does not work for our use case.
We currently use this options on the
dump
method callsbut if we change it to compat, we have 2 problems:
time_format
is not valid for that mode, so we can't keep this change transparent.compat_bigdecimal
to false or true, but that did not work either.How can we get delegate objects to serialize only the underlying object? And not the attributes of the delegate that are anecdotic?
For aditional context, Sequel uses Delegate classes in their implementation and this is causing our problems here: jeremyevans/sequel#2153
Thanks in advance,
Tomas.
The text was updated successfully, but these errors were encountered: