-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Define custom serializer for a class #515
Define custom serializer for a class #515
Conversation
.. by defining #active_model_serializer method on serialized object. Resolves rails-api#515.
.. by defining #active_model_serializer method on serialized object. Resolves rails-api#515.
The |
Yeah, it's okay, but it forces me to create new serializer for every single class, which is unneeded when I f.e. use inheritance with my classes. See my little commit - changes nothing but allows me to be DRY. |
+1 I'd use method |
+1 👍 Better to configure than to pollute the project with files one doesn't need. I'd go the |
+1 I need this too. |
👍 |
.. by defining #active_model_serializer method on serialized object. Resolves rails-api#515.
.. by defining #active_model_serializer method on serialized object. Resolves rails-api#515.
I changed this into |
This is a very tiny patch, so I don't mind adding it. Can I get at least one test though, please? |
I'd like to merge this, but I need a test, plus it needs to be rebased. Please rebase, add a test, and send to the |
.. by defining #serializer_class method in serialized object's class. Resolves rails-api#515.
.. by defining #serializer_class method in serialized object's class. Resolves rails-api#515.
…izer_class method in serialized object's class. Resolves rails-api#515.
How to set a serializer for given class, if I don't want to create another serializer with "xxxSerializer" name?
f.e.
AFAIR there used to be
#serializer_class
method, but seems like it got removed from ActiveModel::Serializer ? Why?If there's no particular reason, I'll send a PR fixing it back.