Description
Hi folks!
In 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.
The idea is very similar to the concept of DataTransformers in the Form component.
We would have a interface that should be implemented by all transformers:
<?php
namespace Symfony\Component\Serializer;
interface AttributeTransformerInterface
{
public function transform($value);
public function reverseTransform($value);
}
The transform
method will be called in the normalization (Similar to the current behavior).
The reverseTransform
will be called in the denormalization.
This will require a new method AbstractNormalizer::setTransformer($attribute, AttributeTransformerInterface $transformer)
.
IMO this can be implemented in a BC way, the idea is deprecate the concept of callbacks in favor of the concept of attribute transformers.