module BSON::Integer
def as_extended_json(**options)
-
(Hash | Integer)
- The extended json representation.
Options Hash:
(**opts)
-
:mode
(nil | :relaxed | :legacy
) -- Serialization mode
def as_extended_json(**options) # The behavior of native integers' serialization to extended json is # not specified. Following our bson serialization logic in this file, # produce explicit $numberInt or $numberLong, choosing $numberInt if # the integer fits in 32 bits. In Ruby integers can be arbitrarily # big; integers that do not fit into 64 bits raise an error as we do not # want to silently perform an effective type conversion of integer -> # decimal. unless bson_int64? raise RangeError, "Integer #{self} is too big to be represented as a MongoDB integer" end if options[:mode] == :relaxed || options[:mode] == :legacy self elsif bson_int32? {'$numberInt' => to_s} else {'$numberLong' => to_s} end end