schmittjoh / serializer

Library for (de-)serializing data of any complexity (supports JSON, and XML)
http://jmsyst.com/libs/serializer
MIT License
2.32k stars 586 forks source link

Accessors at class level for inherited properties #867

Open stollr opened 6 years ago

stollr commented 6 years ago
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no

Virtual properties can be defined at class level. It would be great if this would be possible with accessors, too.

This would be nice for cases where your entity uses traits by third party libraries and you want to put serialization groups to a property inhertied by a trait.

Afaik one has to use YAML config file to achieve this at the moment. If you use YAML for all your entities this is no problem. But if you use annotations it is quite annoying that you have to use YAML for some entities just because of one or two inherited properties.

Example how this could look like:

/**
 * @Serializer\Accessor("name", getter="getTrimmedName",setter="setName")
 * @Serializer\Accessor("firstName", getter="getTrimmedFirstName",setter="setFirstName")
 */
class Author
{
    use PersonTrait;
}

If you like this proposal maybe I'll implement this feature and create a PR.

goetas commented 6 years ago

see http://jmsyst.com/libs/serializer/master/reference/annotations#virtualproperty

stollr commented 6 years ago

@goetas Have you actually read my post completely? Virtual properties cannot be used to set values when deserializing. That's why I talked about accessors.

Please reopen.