I’m using the JMSSerializerBundle in a Symfony2 project, combined with Doctrine2.
I’ve defined a class property as double value, as it represents a product price.
/**
* Price of product
*
* @Type("double")
* @MongoDb\Float */
private $price;
It’s a requirement to display values with trailing zeros (100.00 instead of 100). I’d like to hook this transformation into the deserialization, as the serializer actually knows he’s working with a double value.
Casting all numeric values afterwars won’t work, as there’s other propertys which must not be affected (like quantity, those must stay integer).
Any ideas/hints on this issue?
JMSSerializer bundle allows you to define custom serializer/deserializer handler: http://jmsyst.com/libs/serializer/master/handlers
This allows you to change the way of how a specifc type is being serialized or deserializer.