Shopify/money

to_json, as_json and from_json should behave correctly

bdewater opened this issue · 3 comments

According to the Rails docs:

  • as_json should return a hash of attributes (amount, currency) to be serialized, not a string
  • from_json is missing to assign attributes from a JSON object

We should not override to_json. A great explanation of the difference between as/to_json can be found here: ohler55/oj#199 (comment)

XrXr commented

These docs are for ActiveModel, but Money is not a model. At this point so many things rely on the json encoding on Money it would probably break a lot of things if we tried to make Money serialize into an object in JSON land.

We have some leeway between float and string, because people call to_f on it, but making the leap to an object is a big API change.

I believe these methods are also called on attributes of the model being serialized, which via the way of money_column will happen a lot. Not sure of the various subtle differences between what Rails itself and e.g. ActiveModel::Serializer though.

fixed in v1