-
Notifications
You must be signed in to change notification settings - Fork 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
Serializer should be able to specify serializer class. #112
Comments
One issue is that it actually allows more than one view of the exact same object. Which one should be in the response document then? |
My spontaneous reaction is, if specified on a relationship, use the serializer. Otherwise use the current logic. Yes, this means an object could be included multiple times, if it has multiple representations that are different but included different ways. I'm not certain if that is a feature or a problem. I suppose it may make the implementation a bit more complicated, though I haven't checked to verify. I suppose it also would also allow the inclusion of a parent of a node in a tree structure without having to render all parents. |
(and FWIW, I think it should be an error if two candidate serializers produce the same value in the type field in the output). |
The rationale behind this choice (one serializer per type) is twofold:
Regarding
For that you can have different serializers. You should probably not have different views of the same thing within a given document.
One can simply define it once, and possibly write a wrapper (which is what jsonapi-rails does).
That should be avoided IMO. Sorry for not elaborating more, but I'm quite busy at the moment. Maybe @dawidof has an other opinion? |
Currently, the only way to specify what class to use for when serializing a relationship is to give the renderer the
class
option with a hash with an entry for each serialized resource.In
fast_jsonapi
it is possible to specify that for each relationship in the serializer. Sadly, they have no support for polymorphic relationships and doesn't seem to get support for that anytime soon. Thata: It allows specific different views of the same thing, which allow the database layout to be more decoupled from the jsonapi presentation.
b: For users that doesn't think the default lookup path and naming for serializers are good enough, it allows them to not have to repeat every single serializer every single time they have to serialize something.
c: It allows more than one view of the same type of object in the same serialized response.
So I think it would be extremely nice if it was a feature that was supported.
The text was updated successfully, but these errors were encountered: