jrjackson
jrjackson copied to clipboard
Add an option to serialize BigDecimal as String
Rails serialize BigDecimal as String. If we want to use JrJackson as drop in replacement, we need an option to serialize BigDecimal as String.
Test case:
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'activesupport'
gem 'jrjackson'
end
require 'minitest/autorun'
class MyTest < Minitest::Test
def test_should_be_true
require 'active_support/core_ext/object/json'
obj = {number: BigDecimal.new('123.45')}
assert_equal JSON.dump(obj), JrJackson::Json.dump(obj)
end
end
Output:
1) Failure:
MyTest#test_should_be_true [test.rb:15]:
Expected: "{\"number\":\"123.45\"}"
Actual: "{\"number\":123.45}"
Hello @guyboertje , I saw an open PR for this issue. Could you help look at it? it's appreciated that this issue can be resolved. So we don't need to check every column that used BIGINT(8) in our codebase.
hello @frankwong15 , it would be great to add another optional option for Bignum, or 64 bits integer. Because browser only supports 53 bits integer. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)