-
Notifications
You must be signed in to change notification settings - Fork 56
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
Suggestions on formatting JSON serialization? #86
Comments
I'm not exactly sure what your asking for, but I'm open to adding |
That's pretty much what I'm looking for! Should have clarified more, but say I have a class
Outputting this class to JSON (without any custom serialization) would give me
But I'd love to able to output something like
And, there are ways to do this with custom serializers and such for sure, but was looking for a way to avoid that, as I tend to output my Rails JSON objects without heavy serializers. |
I haven't looked into internals of ActiveRecord lately but I presume the all that would be necessary adding this method to Tod::TimeOfDay: def as_json; to_s; end Maybe you could try monkey patching to see if that does what you want. If it does, I could merge a PR with that method. |
It works as expected
|
Hello! Experimenting with the gem with a basic rails api - any suggestions on a good entry point/mechanism for customizing the JSON output of a ActiveRecord attribute storing a Tod::TimeOfDay? I'd like to show the outpost as a '11:00:00' for example rather than the components.
I'm just using a simple
as_json
for my models. There's lots of ways of doing this of course, adding a method that does the string formatting, using ActiveModelSerializers and overriding the attribute getter, but I'd like to find a higher-level way of customizing the output, if possible. Thank you!The text was updated successfully, but these errors were encountered: