2015-12-18 01:14:52 +08:00
|
|
|
if CANVAS_RAILS4_0
|
|
|
|
ActiveSupport::JSON.backend = :oj
|
|
|
|
MultiJson.dump_options = {:escape_mode => :xss_safe}
|
2013-08-22 06:46:05 +08:00
|
|
|
|
2015-12-18 01:14:52 +08:00
|
|
|
# Rails4 gives an option to opt out of encoding BigDecimal json as a string
|
|
|
|
if ActiveSupport.respond_to?(:encode_big_decimal_as_string)
|
|
|
|
ActiveSupport.encode_big_decimal_as_string = false
|
2013-10-20 01:14:31 +08:00
|
|
|
|
2015-12-18 01:14:52 +08:00
|
|
|
# Rails3 changes BigDecimal #to_json to encode as a string. This breaks
|
|
|
|
# bw-compat in our apis, so this switches it back to the native behavior.
|
|
|
|
else
|
|
|
|
require 'bigdecimal'
|
2014-07-24 01:14:22 +08:00
|
|
|
|
2015-12-18 01:14:52 +08:00
|
|
|
class BigDecimal
|
|
|
|
def as_json(options = nil)
|
|
|
|
if finite?
|
|
|
|
self
|
|
|
|
else
|
|
|
|
NilClass::AS_JSON
|
|
|
|
end
|
2014-02-26 07:50:31 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-12-18 22:15:07 +08:00
|
|
|
else
|
|
|
|
require 'json/jwt'
|
|
|
|
require 'oj_mimic_json' # have to load after json/jwt or else the oj_mimic_json will make it never load
|
2015-12-18 01:14:52 +08:00
|
|
|
end
|