Uploaded image for project: 'Couchbase Ruby client library'
  1. Couchbase Ruby client library
  2. RCBC-34

Using Yajl json_gem compatibility breaks compatibility with many gems and applications

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2.0.dp3
    • Component/s: None
    • Security Level: Public
    • Labels:
      None

      Description

      json_gem compatibility (require 'yajl/json_gem') is notorious for causing all kinds of issues with various gems. The most compatible way to use yajl is to call Yajl::Parser and Yajl::Encoder directly.

      So far I only see tests that are using JSON.dump

      No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

        Hide
        avsej Sergey Avseyev added a comment -

        Thanks for feedback,

        Does it make situation better if I'll use https://github.com/intridea/multi_json ?

        Show
        avsej Sergey Avseyev added a comment - Thanks for feedback, Does it make situation better if I'll use https://github.com/intridea/multi_json ?
        Hide
        bpoweski Ben Poweski added a comment -

        MultiJson would be better than using json_gem compatibility (Rails uses mulit_json to abstract json parsers). In this case though I don't think you even need to pull that dependency. If you just use Yajl::Parser and Yajl::Encoder directly you can skirt the entire problem.

        If you look at the the json_gem.rb file it really doesn't provide much functionality.

        def self.generate(obj, opts={})
        begin
        options_map = {}
        if opts.has_key?(:indent)
        options_map[:pretty] = true
        options_map[:indent] = opts[:indent]
        end
        Yajl::Encoder.encode(obj, options_map)
        rescue Yajl::EncodeError => e
        raise JSON::GeneratorError, e.message
        end
        end

        def self.pretty_generate(obj, opts={})
        begin
        options_map = {}
        options_map[:pretty] = true
        options_map[:indent] = opts[:indent] if opts.has_key?(:indent)
        Yajl::Encoder.encode(obj, options_map)
        rescue Yajl::EncodeError => e
        raise JSON::GeneratorError, e.message
        end
        end

        def self.dump(obj, io=nil, *args)
        begin
        Yajl::Encoder.encode(obj, io)
        rescue Yajl::EncodeError => e
        raise JSON::GeneratorError, e.message
        end
        end

        Show
        bpoweski Ben Poweski added a comment - MultiJson would be better than using json_gem compatibility (Rails uses mulit_json to abstract json parsers). In this case though I don't think you even need to pull that dependency. If you just use Yajl::Parser and Yajl::Encoder directly you can skirt the entire problem. If you look at the the json_gem.rb file it really doesn't provide much functionality. def self.generate(obj, opts={}) begin options_map = {} if opts.has_key?(:indent) options_map [:pretty] = true options_map [:indent] = opts [:indent] end Yajl::Encoder.encode(obj, options_map) rescue Yajl::EncodeError => e raise JSON::GeneratorError, e.message end end def self.pretty_generate(obj, opts={}) begin options_map = {} options_map [:pretty] = true options_map [:indent] = opts [:indent] if opts.has_key?(:indent) Yajl::Encoder.encode(obj, options_map) rescue Yajl::EncodeError => e raise JSON::GeneratorError, e.message end end def self.dump(obj, io=nil, *args) begin Yajl::Encoder.encode(obj, io) rescue Yajl::EncodeError => e raise JSON::GeneratorError, e.message end end
        Hide
        avsej Sergey Avseyev added a comment -

        Uploaded to review site http://review.couchbase.org/16153

        Show
        avsej Sergey Avseyev added a comment - Uploaded to review site http://review.couchbase.org/16153
        Hide
        bpoweski Ben Poweski added a comment -

        There is special handing for the json gem in rails thus breaking capability when the json_gem file is loaded after rails is

        https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/object/to_json.rb

        We worked around the issue by requiring yajl/json_gem before loading actives active support but this could have very well unknowingly break the driver.

        Show
        bpoweski Ben Poweski added a comment - There is special handing for the json gem in rails thus breaking capability when the json_gem file is loaded after rails is https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/object/to_json.rb We worked around the issue by requiring yajl/json_gem before loading actives active support but this could have very well unknowingly break the driver.
        Hide
        avsej Sergey Avseyev added a comment -

        Now couchbase gem depends on only MultiJson and uses dump/load everywhere. Could you check current master version from github?

        Show
        avsej Sergey Avseyev added a comment - Now couchbase gem depends on only MultiJson and uses dump/load everywhere. Could you check current master version from github?

          People

          • Assignee:
            avsej Sergey Avseyev
            Reporter:
            bpoweski Ben Poweski
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Gerrit Reviews

              There are no open Gerrit changes