{"action":"closed","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/15761","labels_url":"https://api.github.com/repos/symfony/symfony/issues/15761/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/15761/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/15761/events","html_url":"https://github.com/symfony/symfony/issues/15761","id":105941112,"number":15761,"title":"[Serializer] Introduce the concept of AttributeTransformer","user":{"login":"dosten","id":510842,"avatar_url":"https://avatars.githubusercontent.com/u/510842?v=3","gravatar_id":"","url":"https://api.github.com/users/dosten","html_url":"https://github.com/dosten","followers_url":"https://api.github.com/users/dosten/followers","following_url":"https://api.github.com/users/dosten/following{/other_user}","gists_url":"https://api.github.com/users/dosten/gists{/gist_id}","starred_url":"https://api.github.com/users/dosten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dosten/subscriptions","organizations_url":"https://api.github.com/users/dosten/orgs","repos_url":"https://api.github.com/users/dosten/repos","events_url":"https://api.github.com/users/dosten/events{/privacy}","received_events_url":"https://api.github.com/users/dosten/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/symfony/symfony/labels/Serializer","name":"Serializer","color":"DDDDDD"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-09-11T03:59:09Z","updated_at":"2015-11-28T16:39:40Z","closed_at":"2015-11-28T16:39:40Z","body":"Hi folks!\r\n\r\nIn a recent project I found that if some define a callback when normalize a object (i.e. Convert a DateTime object to a ISO8601 string) there isn't a easy way to convert the ISO8601 string into a DateTime object, so, I propose to introduce the concept of AttributeTransformers as a replacement of the concept of callbacks.\r\nThe idea is very similar to the concept of DataTransformers in the Form component.\r\nWe would have a interface that should be implemented by all transformers:\r\n\r\n```php\r\n<?php\r\n\r\nnamespace Symfony\\Component\\Serializer;\r\n\r\ninterface AttributeTransformerInterface\r\n{\r\n    public function transform($value);\r\n    public function reverseTransform($value);\r\n}\r\n```\r\n\r\nThe `transform` method will be called in the normalization (Similar to the current behavior).\r\nThe `reverseTransform` will be called in the denormalization.\r\n\r\nThis will require a new method `AbstractNormalizer::setTransformer($attribute, AttributeTransformerInterface $transformer)`.\r\n\r\nIMO this can be implemented in a BC way, the idea is deprecate the concept of callbacks in favor of the concept of attribute transformers."}}