You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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?
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 specifypublic_method
over and over again in the configuration of each class.The text was updated successfully, but these errors were encountered: