I've an entity I usually serialize using the JMS Serializer bundle. I have to add to the serialization some fields that doesn't reside in the entity itself but are gathered with some db queries.
My idea was to create a custom object, fill the fields with the entity fields and add the custom one. But this seems a bit tricky and expensive to do for every variation (I use lot of serialization groups) of the class.
Is there a better/standard way to do this? Using a factory? Pre/Post serialization events?
Maybe I can listen for the serialization and checking entity type and serialization groups add the custom fields? But instead of making a query for each entity it would be better to gather all the data of the related entities and then add it to them. Any help is appreciated
question from:https://stackoverflow.com/questions/15007281/add-extra-fields-using-jms-serializer-bundle