title: PHP, How to customize the serialization of an array of dates using JMS Serializer (or Symfony Serializer)
body: <p>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:</p>
  
  <pre><code>$serializer = SerializerBuilder::create()-&gt;build();
  $dates = array(new DateTime('1990-07-20'), new DateTime('2000-07-20'));
  $serialized = $serializer-&gt;serialize($dates, 'xml');
  </code></pre>
  
  <p>Currently I get something like:</p>
  
  <pre><code>&lt;result&gt;
    &lt;entry&gt;&lt;![CDATA[1990-07-20T00:00:00+0000]]&gt;&lt;entry/&gt;
    &lt;entry&gt;&lt;![CDATA[2000-07-20T00:00:00+0000]]&gt;&lt;entry/&gt;
  &lt;/result&gt;
  </code></pre>
  
  <p>I want to configure things like: differnt tags, differnt format for the dates, get
  rid of the CDATA. And get something like this:</p>
  
  <pre><code>  &lt;dates&gt;
      &lt;date&gt;1990-07-20&lt;date/&gt;
      &lt;date&gt;2000-07-20&lt;date/&gt;
    &lt;/dates&gt;
  </code></pre>
  
  <hr>
  
  <p>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! </p>