Currently, the default serialization of a Money object results in an object with keys of cents and currency_iso:
m = Money.new(1000, 'USD')
m.to_json
=> "{\"cents\":1000, \"currency_iso\":\"USD\"}"
This is implemented by defining to_hash on Money here:
|
{ cents: cents, currency_iso: currency.iso_code.to_s } |
The serialization is awkward for currencies that don't include cents, for example JPY:
m = Money.new(1000, 'JPY')
m.to_json
=> "{\"cents\":1000, \"currency_iso\":\"JPY\"}"
Is there any openness to adding a config option that would allow for customizing this behavior? E.g. config.amount_serialization_key = :amount could result in:
m = Money.new(1000, 'JPY')
m.to_json
=> "{\"amount\":1000, \"currency_iso\":\"JPY\"}"
Currently, the default serialization of a Money object results in an object with keys of
centsandcurrency_iso:This is implemented by defining
to_hashon Money here:money-rails/lib/money-rails/money.rb
Line 27 in 79df005
The serialization is awkward for currencies that don't include cents, for example JPY:
Is there any openness to adding a config option that would allow for customizing this behavior? E.g.
config.amount_serialization_key = :amountcould result in: