Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Stack error with Hash.to_json for nested number values

#652

Here's the test

    hash = {
      "CHI" => {
        :dislay_name => "chicago",
        :latitude => 123.234
      }
    }
    result = hash.to_json

And the result

Error:
test: Institution should output json. (InstitutionTest):
SystemStackError: stack level too deep
    /Users/noel/Projects/botanic/plant_collections/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/json/encoding.rb:29

Poking around, converting the number to a string did not trigger the problem, and using a flat hash rather than a nested hash also did not. I'm wondering if this is a odd side effect of the stack check to avoid circular references?

Reported by Noel Rappin · July 18th, 2008 @ 04:51 PM

State: committed
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Dan Barry
    Dan Barry
    • Tag changed from 2.1, activesupport, bug to 2.1, activesupport, bug

    I wrote a unit test for this that passed on edge rails, so it looks like this has been fixed already.

    October 12th, 2008 @ 09:42 PM

  2. Repository
    Repository
    • State changed from new to committed

    (from [0d4dbb3dfaec8355e072d8f758de40a277f2f009]) test nested hash with float

    [#652 Stack error with Hash.to_json for nested number values state:committed]

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...

    October 12th, 2008 @ 10:25 PM

  3. Noel Rappin
    Noel Rappin
    • Tag changed from 2.1, activesupport, bug to 2.1, activesupport, json

    Oddly, I'm still having the problem, with Rails 2.2. Just saw it when trying to run the open flash chart example,

    http://pullmonkey.com/projects/o...

    The resulting JSON should look like this

    {"title": "Tasker", "elements": [{"type": "bar_glass", "values": [1, 2]}]}

    But I'm getting the same stack overflow error. The original example doesn't work for me either.

    noel$ script/console Loading development environment (Rails 2.2.2)

    hash = { ?> "CHI" => { ?> :dislay_name => "chicago", ?> :latitude => 123.234

          }
        }
    
    

    => {"CHI"=>{:dislay_name=>"chicago", :latitude=>123.234}}

        result = hash.to_json
    
    

    December 1st, 2008 @ 08:14 PM

  4. Noel Rappin
    Noel Rappin

    Asking around my group, the original example works for some of us, but not for others in a script/console session.

    December 1st, 2008 @ 08:16 PM