Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_json, as_json and from_json should behave correctly #76

Closed
bdewater opened this issue Jul 14, 2017 · 3 comments
Closed

to_json, as_json and from_json should behave correctly #76

bdewater opened this issue Jul 14, 2017 · 3 comments
Milestone

Comments

@bdewater
Copy link
Contributor

bdewater commented Jul 14, 2017

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
Copy link
Contributor

XrXr commented Sep 17, 2018

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.

@bdewater
Copy link
Contributor Author

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.

@elfassy
Copy link
Contributor

elfassy commented Oct 11, 2023

fixed in v1

@elfassy elfassy closed this as completed Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants