support MongoDB extended JSON on ObjectID#to_json
This commit is contained in:
parent
05342ef8f2
commit
d71f7d4e3a
|
@ -142,8 +142,12 @@ module Mongo
|
|||
end
|
||||
alias_method :inspect, :to_s
|
||||
|
||||
def to_json(*args)
|
||||
%Q("#{to_s}")
|
||||
# Convert to MongoDB extended JSON format. Since JSON includes type information,
|
||||
# but lacks an ObjectID type, this JSON format encodes the type using an $id key.
|
||||
#
|
||||
# @return [String] the object id represented as MongoDB extended JSON.
|
||||
def to_json(escaped=false)
|
||||
"{\"$oid\": \"#{to_s}\"}"
|
||||
end
|
||||
|
||||
# @deprecated
|
||||
|
|
|
@ -151,6 +151,6 @@ class ObjectIDTest < Test::Unit::TestCase
|
|||
|
||||
def test_json
|
||||
id = ObjectID.new
|
||||
assert_equal %Q("#{id}"), id.to_json
|
||||
assert_equal "{\"$oid\": \"#{id}\"}", id.to_json
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue