Git Product home page Git Product logo

activesupport-json_encoder's Issues

Unable to install the gem for rails 5.1.4 & ruby 2.3.3

Bundler could not find compatible versions for gem
"activesupport":
In Gemfile:
activesupport-json_encoder was resolved to 1.0.0, which
depends on
activesupport (< 5.0, >= 4.1.0.beta)

rails (~> 5.1.4) was resolved to 5.1.4, which depends on
  activesupport (= 5.1.4)

spring was resolved to 2.0.2, which depends on
  activesupport (>= 4.2)

Bundler could not find compatible versions for gem "rails":
In Gemfile:
rails (~> 5.1.4)

Could not find gem 'rails (~> 5.1.4)' in any of the sources.

Unable to use JSON.pretty_print when using plain objects w/ as_json.

Here's an example:
https://gist.github.com/msavy/884642ff7a8b835a4d9e

Note, I'm not using Rails. It works nicely if the objects extend hash, as in your tests, but not if you're just implementing as_json(options={})

$ bundle exec ruby ticket.rb
# to_json
{"obja":{"whynot":"zoidberg","this":"string"}}
# JSON.pretty_generate
/Library/Ruby/Gems/2.0.0/gems/json-1.8.1/lib/json/common.rb:285:in `generate': only generation of JSON objects or arrays allowed (JSON::GeneratorError)
    from /Library/Ruby/Gems/2.0.0/gems/json-1.8.1/lib/json/common.rb:285:in `pretty_generate'
    from ticket.rb:28:in `<main>'

Side-note: Apologies for initially empty ticket as I lost the focus on the input box without noticing, so when I hit enter I posted the new issue before I was finished!

Can't install in Rails 5.0.1

I'm trying to add this gem so I can get the encode_big_decimal_as_string option back, but when I try to bundle install I get:

Bundler could not find compatible versions for gem "activesupport":
  In Gemfile:
    activesupport-json_encoder was resolved to 1.0.0, which depends on
      activesupport (< 5.0, >= 4.1.0.beta)

Seems like it's set to require Rails 4. Is there another solution for Rails 5?

Rails 5, beta 3: undefined method `encode_big_decimal_as_string='

Since encode_big_decimal_as_string was deprecated in Rails 5, we now get an error message:

/vagrant/config/environment.rb:4:in `<top (required)>': undefined method `encode_big_decimal_as_string=' for ActiveSupport:Module (NoMethodError)
    from /var/lib/gems/2.2.0/gems/activesupport-5.0.0.beta3/lib/active_support/dependencies.rb:302:in `require'
    from /var/lib/gems/2.2.0/gems/activesupport-5.0.0.beta3/lib/active_support/dependencies.rb:302:in `block in require'
    from /var/lib/gems/2.2.0/gems/activesupport-5.0.0.beta3/lib/active_support/dependencies.rb:268:in `load_dependency'
    from /var/lib/gems/2.2.0/gems/activesupport-5.0.0.beta3/lib/active_support/dependencies.rb:302:in `require'
    from /vagrant/config.ru:3:in `block in <main>'
    from /home/vagrant/.bundler/ruby/2.2.0/rack-ea2ed578c368/lib/rack/builder.rb:55:in `instance_eval'
    from /home/vagrant/.bundler/ruby/2.2.0/rack-ea2ed578c368/lib/rack/builder.rb:55:in `initialize'

Code:

ActiveSupport.encode_big_decimal_as_string = false

"stack level too deep" error

I try to use this to get custom json & always get "stack level too deep" error
I try to use irb like

require 'active_support'
ActiveSupport.version #=> version : 4.1.6
require 'active_support/json/encoding/active_support_encoder'

#same as README demo
class Money
  def initialize(dollars, cents)
    @dollars = dollars
    @cents = cents
  end
  def as_json(options = nil)
    self
  end
  def encode_json(encoder)
    if @cents.to_i < 10
      "#{@dollars.to_i}.0#{@cents.to_i}"
    else
      "#{@dollars.to_i}.#{@cents.to_i}"
    end
  end
end

{ price: Money.new(0,10) }.to_json #=> stack level too deep

can you fix it? & my ruby : ruby 2.1.2

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.