jrjackson icon indicating copy to clipboard operation
jrjackson copied to clipboard

Add an option to serialize BigDecimal as String

Open frankwong15 opened this issue 8 years ago • 2 comments

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}"

frankwong15 avatar Dec 25 '16 13:12 frankwong15

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.

respire avatar Mar 13 '18 04:03 respire

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)

respire avatar Mar 13 '18 04:03 respire