global_phone icon indicating copy to clipboard operation
global_phone copied to clipboard

GlobalPhone::Number.to_json throws CircularReferenceError

Open kirkchris opened this issue 10 years ago • 0 comments

Calling .to_json on a GlobalPhone::Number throws a CircularReferenceError. This is in Rails v4.0.5 with Ruby v.1.9.3.

1.9.3-p547 :001 > number = GlobalPhone.parse("6541238888") => #<GlobalPhone::Number territory=#<GlobalPhone::Territory country_code=1 name=US> national_string="6541238888"> 1.9.3-p547 :002 > number.to_json ActiveSupport::JSON::Encoding::CircularReferenceError: object references itself from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:79:in check_for_circular_references' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:49:inencode' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:306:in block in encode_json' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:306:ineach' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:306:in map' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:306:inencode_json' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:275:in block in encode_json' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:275:inmap' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:275:in encode_json' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:51:inblock in encode' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:81:in check_for_circular_references' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:49:inencode' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:306:in block in encode_json' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:306:ineach' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:306:in map' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:306:inencode_json' ... 9 levels... from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:49:in encode' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:306:inblock in encode_json' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:306:in each' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:306:inmap' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:306:in encode_json' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:51:inblock in encode' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:81:in check_for_circular_references' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:49:inencode' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/json/encoding.rb:34:in encode' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.0.5/lib/active_support/core_ext/object/to_json.rb:16:into_json' from (irb):2 from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/railties-4.0.5/lib/rails/commands/console.rb:90:in start' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/railties-4.0.5/lib/rails/commands/console.rb:9:instart' from /Users/chris/.rvm/gems/ruby-1.9.3-p547/gems/railties-4.0.5/lib/rails/commands.rb:62:in <top (required)>' from bin/rails:4:inrequire' from bin/rails:4:in `

'1.9.3-p547

kirkchris avatar Sep 18 '14 18:09 kirkchris