Open
Description
Description
Similar how we can add custom validator annotations (https://symfony.com/doc/current/validation/custom_constraint.html), it would be beneficial to be able to create custom serialization annotations to augment existing functionality on a per-property/method basis.
Right now, Groups
, SerializedName
, and Ignore
are all hard-coded into the serialization process via the AttributeMetadaInterface
, AnnotationLoader
, and the ClassMetadataInterface
. There is no easy or intuitive way to create and use custom annotations currently that I have found (If I'm mistaken, I'd love to hear more).
Example
Two use cases:
- Encryption: we sometimes serialize personally-identifiable-information (PII) as part of a data transfer process from an API to a consumer endpoint. However, for obvious security reasons, we encrypt this PII so if it is intercepted during transmission then the data is still secure. When calling the serialize process, we have to leak our implementation by designating which fields of our models and entities need to be encrypted (typically in the controller). Instead, it would be nice to write an
@Encrypt()
annotation that can decorate the properties inside of the entities themselves and automatically encrypt - similar to how@Ignore
or@SerializedName
works. - Dates: While we can globally set a specific date format for our
DateTime
instances, there are some circumstances where we need to arbitrarily send back a date in a different format (e.g., just a date or a date with a time or a date/time with timezone information).
Thank you.