Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Serializer] Ability to add custom annotations #38993

Copy link
Copy link
Open
@d42ohpaz

Description

@d42ohpaz
Issue body actions

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:

  1. 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.
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.