diff --git a/lib/bson/types/objectid.rb b/lib/bson/types/objectid.rb index edb7ff3..30b179b 100644 --- a/lib/bson/types/objectid.rb +++ b/lib/bson/types/objectid.rb @@ -140,7 +140,7 @@ module BSON # but lacks an ObjectID type, this JSON format encodes the type using an $oid key. # # @return [String] the object id represented as MongoDB extended JSON. - def to_json(escaped=false) + def to_json(*a) "{\"$oid\": \"#{to_s}\"}" end diff --git a/test/mongo_bson/json_test.rb b/test/mongo_bson/json_test.rb new file mode 100644 index 0000000..441064b --- /dev/null +++ b/test/mongo_bson/json_test.rb @@ -0,0 +1,16 @@ +require 'test/test_helper' +require 'rubygems' +require 'json' + +class JSONTest < Test::Unit::TestCase + + include Mongo + include BSON + + def test_object_id_as_json + id = ObjectID.new + obj = {'_id' => id} + assert_equal "{\"_id\":{\"$oid\": \"#{id.to_s}\"}}", obj.to_json + end + +end