I need to serialize an array of dates (just that, not an object containing the array of dates!) and I want to be able to control how it is done:
$serializer = SerializerBuilder::create()->build();
$dates = array(new DateTime('1990-07-20'), new DateTime('2000-07-20'));
$serialized = $serializer->serialize($dates, 'xml');
Currently I get something like:
<result>
<entry><![CDATA[1990-07-20T00:00:00+0000]]><entry/>
<entry><![CDATA[2000-07-20T00:00:00+0000]]><entry/>
</result>
I want to configure things like: differnt tags, differnt format for the dates, get rid of the CDATA. And get something like this:
<dates>
<date>1990-07-20<date/>
<date>2000-07-20<date/>
</dates>
One option I am considering is creating a Dates object that contains the array. Then I can use annotations or even a custom handler to add format to the dates and also describe the xml tags. But I think there should be an easier way. I really don't want to create a wrapper object just to tell how an array of dates should be serialized. It is not a terrible solution though. But let me know if you think of a better one or answer the above question. Thanks!