Giter VIP home page Giter VIP logo

Comments (6)

beerlington avatar beerlington commented on August 28, 2024

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.

from classy_enum.

beerlington avatar beerlington commented on August 28, 2024

Which version of the gem are you currently using?

from classy_enum.

ghostd avatar ghostd commented on August 28, 2024

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:

  • to encode the enum to_json calls the JSON encoder
    (see lib/active_support/core_ext/object/to_json.rb)
  • which calls as_json
    (see lib/active_support/json/encoding.rb)
  • which calls "instance_values" for the enum
    (see Object#as_json overriding in lib/active_support/json/encoding.rb)
  • which returns all properties including the owner (the loop is now created)

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

from classy_enum.

beerlington avatar beerlington commented on August 28, 2024

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

Diff: master..._fix-json-recursion

from classy_enum.

ghostd avatar ghostd commented on August 28, 2024

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)

from classy_enum.

beerlington avatar beerlington commented on August 28, 2024

Just pushed v 1.3.1 which fixes this issue. Thanks for reporting it.

from classy_enum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.