You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
The text was updated successfully, but these errors were encountered:
The normalizer converts a whole object into an array, a transformer convert a single property of this object into any thing you want (i.e A DateTime object into a ISO8601 string). Think that a transformer is an extended version of the "callbacks" provided by normalizers (http://symfony.com/doc/current/components/serializer.html#using-callbacks-to-serialize-properties-with-object-instances) but the callbacks only works in the normalization, if you want to denormalize an array into an object, you can't.
I see. But if I had a normalizer that handles DateTime instances and a mechanism to indicate the type of a certain property (like described in #14844 for instance), would I still need those transformers?
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:
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.
The text was updated successfully, but these errors were encountered: