Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2947

to_json should behave like vanilla Moped, or at least be consistent when used in an array (or hash)

    • Type: Icon: Task Task
    • Resolution: Done
    • 4.0.0 final
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Consider this test program:

      #!/usr/bin/env ruby
      require 'json'
      require 'moped'
      puts Moped::BSON::ObjectId.new.to_json
      puts [Moped::BSON::ObjectId.new].to_json
      require 'mongoid'
      puts Moped::BSON::ObjectId.new.to_json
      puts [Moped::BSON::ObjectId.new].to_json
      

      The output with the current Mongoid is:

      $ ./test.rb
      {"$oid": "516224fe9fc87efb83000001"}
      [{"$oid": "516224fe9fc87efb83000002"}]
      {"$oid": "516224fe9fc87efb83000003"}
      ["516224fe9fc87efb83000004"]
      

      The output with this commit applied:

      $ ./test.rb
      {"$oid": "516225259fc87e6200000001"}
      [{"$oid": "516225259fc87e6200000002"}]
      {"$oid": "516225259fc87e6200000003"}
      [{"$oid":"516225259fc87e6200000004"}]
      

      Note that this commit does not break any tests.

      The sad thing is that this commit may break existing systems. The other route is to stop doing $oid tricks in Moped, but that would break existing systems as well.

            Assignee:
            durran Durran Jordan
            Reporter:
            nviennot nviennot
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: