Skip to content

Change default access_type globally #336

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

Closed
ianfp opened this issue Sep 15, 2014 · 2 comments
Closed

Change default access_type globally #336

ianfp opened this issue Sep 15, 2014 · 2 comments

Comments

@ianfp
Copy link

ianfp commented Sep 15, 2014

Is there some way to tell the serializer to always use the public_method access type for all classes/entities? I never want it to access my private properties (indeed, that seems like a strange default setting), but I'd prefer not to have to specify public_method over and over again in the configuration of each class.

@schmittjoh
Copy link
Owner

No there is no way.

To explain the reasoning behind the default a bit. A serializer tries to capture the state of an object, transform that state into a representation that can be stored/transmitted elsewhere, and then be reconstructed. After reconstruction, the object should - at best - be in the same state that it was originally in. As such not going through the public API of an object which potentially modifies its state or data perfectly makes sense.

I can see that this might not be a concern of yours if you are not consuming the transformed representation, but the serializer was originally created for this use-case, and extended to other use-cases afterwards. It also has not been a big problem in practice.

Anyway, closing.

@ianfp
Copy link
Author

ianfp commented Sep 16, 2014

Thanks for the explanation. That does make the defaults seem reasonable.

In my case, I'm using the serializer primarily for a REST API, so I only want the object's public interface to be exposed. (After all, how much more "public" than an web API can you get?) The consumers of my API will have no need to restore the original objects.

I feel like using the serializer for REST APIs is a very common use case. Would it be difficult to add this feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants