-
Notifications
You must be signed in to change notification settings - Fork 27
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
CircularReferenceError with rails 'to_json' method #6
Comments
I looked into this a little but was getting a stack level too deep error, and not a CircularReferenceError. Perhaps it's the same thing? Either way, it should be an easy fix by just filtering out the owner from the json response as you suggested. I should have a patched version of the gem ready in the next day or so. |
Which version of the gem are you currently using? |
Hi, I got this issue with rails 3.1.0 and 3.1.1. I get a "stack level too deep error" when i try with web pages, and when i investigated in a rails console, i got a CircularReferenceError. I went more in depth about this error, here is what i found to explain the problem:
I think you should proivde a "as_json" implementation for the Enum base class. PS: i think you should not package your .rvmrc in the gem... it makes warning when i go through the gems directories with mine |
Thanks for the info. I pushed a fix to a new branch and I was hoping you could try it out and see if it addresses your specific issue. https://github.com/beerlington/classy_enum/tree/_fix-json-recursion |
It works here! I'm going to continue to override 'as_json' because i need both values: symbol and name (since name is a method, it's not included by the introspection) |
Just pushed v 1.3.1 which fixes this issue. Thanks for reporting it. |
Hi,
I added an enum to my (working) class, and now i get CircularReferenceError when i try to convert my instance into JSON.
By default class is serialized with the enum, which is serialized with the owner... which is serialized with the enum :-)
I think the generator (or the base class) should override as_json to except the owner attribute.
I did this into by base enum class:
def as_json(options = {})
{:sym => to_s, :name => name}
end
The text was updated successfully, but these errors were encountered: