-
Notifications
You must be signed in to change notification settings - Fork 351
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
[RFC] Extending JSON API Serializer #234
[RFC] Extending JSON API Serializer #234
Conversation
Why do you extend? Just aggregate and implement the interface. |
Hi @prolic, Well, for starters, why implement a fullblown serializer, when what I need is already there, but just needs a minor tweak? And also, why not? And then there's the DRY thing, too. Basically, I need to inject Check here to see what I mean. So, the current issue here is that besides having to make the change I want to the And while I reckon the pull request should make more sense now. |
You can implement the interface and proxy all methods to the aggregated original serializer. This is done in seconds. Than you can implement needed changes in your new class. Extending classes is a bad thing in most situation, that's also why there are private functions. I would rather suggest making the JsonApiSerializer class final. Further reading: http://ocramius.github.io/blog/when-to-declare-classes-final/ |
There are some valid points in that article you mentioned, and I do get that all the methods I had to reimplement are specific to the You could say that extending the Also, if we want to prevent the inheritance chain of doom, wouldn't the Anyway, I'll try your suggestion with proxying the methods and see how it goes. |
The proxy manager is for other use cases. Take a look at this gist. You can use it and change the methods you need. Best |
Thanks for your reply @prolic, although from what I can see, that's just a wrapper around the The issue I'm facing is with the logic in the And I don't see other way of doing it without extending the class. |
But the private method must be called from a public one. Otherwise it would never be called. |
Just rewrite the public method, private methods are only an implementation detail. |
Yes, I understand that, but there's no way to change the current behaviour of the private method from the outside, is there? Look at the code and tell me how do I add another property to go along with
As it stands, this implementation detail is limiting us to a subset of the JSON API spec. Mind you, I'm well aware that the complete spec isn't yet implemented in the Do make an effort to understand that not all design patterns and ideologies apply to everything. Can anyone else comment on this? @philsturgeon, @jasonlewis ? |
|
Hmm, the only thing @quetzyg want is to inject "meta" in the I agree that just making all the private methods protected is overkill and makes it harder to change the class in the future (as now you have an BC promise for this class that can't be broken without a major version bump). Using a proxy or decorator (to be exact) is also an option but will require much more work, and will require a deep knowledge about the returned structure. |
[RFC] Extending JSON API Serializer
Appreciated @willishq! |
Hi,
This PR changes the visibility of some methods of the JsonApiSerializer class, so that it's easier to extend from.
PS: Made a new PR to comply with the rules (i.e. do not PR from
master
branch).