-
Notifications
You must be signed in to change notification settings - Fork 90
Included assuming default class name to build Serializers #35
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
Comments
Per the docs, use |
@fotinakis thanks for reply. I've tried with JSONAPI::Serializer.serialize(
requester,
include: ['mailing_address', 'shipping_address']
) # fail with the error above. |
After looking through the code I'm not sure if we support this very well. You may want to try passing through the JSONAPI::Serializer.serialize(requester, serializer: My::Awesome::Responders::Requester) But, I'm not sure if relationships will work well. There are some architecture changes we need to make to support this (somewhat discussed in #18) -- sorry we don't have a better answer for this namespace handling right now. |
@fotinakis I've read some code and had tested this option as well. I saw there is some dependency with Thanks! |
Actually #18 is still open, what looks closed at the bottom is a related issue. And the ActiveSupport dependency has been discussed here: #33 (but that is not related to this issue). I think the best fix here is to add support like mentioned in #18 (comment) for defining a method on objects called I've added this here: #37 Can you try this and let me know if it works for you? It's in the If that works for you, I'll add documentation and merge it in. |
@hlegius Let me know if you have time to test the |
@fotinakis sure, no probls! I'll do it this along this week and keep you posted here. |
@fotinakis sorry for delay. It worked as expected (in the Specs). Thanks! 💯 Just one thought about it: I needed to kinda couple my Entity in its Serializer. i.e. class User
# entity class (inside domain layer)
def initialize(..)
end
def entity_method...
end
def jsonapi_serializer_class_name
# UserRepresenter class name
end
end
class UserRepresenter
# serializer (inside Presentation layer)
attribute :full_name
end It creates a dependency multi-tier between User (as Entity) and UserRepresenter (as Serializer) It would bring us some complexity later if we need to split both application tiers physically. What do you think about it? As far as I read user_representer = My::Weird::Namespace::UserRepresenter.new(user_entity)
JSONAPI::Serializer.serialize(user_representer, included: ['posts']) What's your thoughts/concerns about it? Thanks again for the fast solution o/ |
Any news on this one? Thanks! |
Just merged #37 and updated the README with docs. Released as gem v0.5.0. Thanks! |
Hello there!
I am trying to build a
included
JSON API schema within my Serializer, but I am got an error while try to find the serializer class.I've got:
My implementation:
So, as far as I've debugged, it's when ActiveSupport
.constantize
that tries to build aSome::Other::Namespace::RequesterSerializer
with some fixed convention created withinserialize.rb
file.Documentation says that it's possible to customize this behavior, but I didn't figure out who to do this.
If you need further informations, I am totally willing to help to understand/solve this o/
Thanks for reading!
The text was updated successfully, but these errors were encountered: