global_phone
global_phone copied to clipboard
GlobalPhone::Number.to_json throws CircularReferenceError
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:in
encode'
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:in
each'
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: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: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:in
map'
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:in
block 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:in
encode'
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:in
each'
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:in
encode_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: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:in each' 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: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:in
block 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:in
encode'
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:in
to_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:in
start'
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:in
require'
from bin/rails:4:in `