Symfony 3 - automatically serialize DateTime object
<p>In my project I have some entity with <code>createdAt</code> column. </p>

<pre><code>//...
class Acme
{
    /**
     * @var DateTime
     *
     * @ORM\Column(name="created_at", type="datetime")
     */
    protected $createdAt;
}
</code></pre>

<p>I have enabled <code>FOSRestBundle</code> with Symfony serializer:</p>

<pre><code>fos_rest:
    disable_csrf_role: ROLE_API
    param_fetcher_listener: true
    body_listener: true
    format_listener:
        rules:
            - { path: '/', fallback_format: json, prefer_extension: false }
    routing_loader:
        default_format: json
        include_format: false
    view:
        view_response_listener: force
</code></pre>

<p>I make select from datebase in <code>AcmeRepository</code>: </p>

<pre><code>public function methodName() 
{
   $qb =  $this-&gt;createQueryBuilder('d');
   $s = $qb-&gt;select('d.createdAt']);

   return $s-&gt;getQuery()-&gt;getArrayResult();
}
</code></pre>

<p>And in result, in my controller:</p>

<pre><code>$res = $em-&gt;getRepository('AppBundle:Acme')-&gt;methodName();
return $res;
</code></pre>

<p>It's returns json, but instead of <code>[{"created_at": "2016-04-04 12:13:13"}]</code>  i'm getting this: </p>

<pre><code>[{"created_at":{"timezone":{"name":"UTC","location":{"country_code":"??","latitude":0,"longitude":0,"comments":""}},"offset":0,"timestamp":1459769277}]
</code></pre>

<p>How I can fix this?</p>