I'm trying to build an API with FOSRestBundle and JMSSerializerBundle on Symfony2. I succeeded to run it with json output perfectly. But the XML output is not good. It runs, produce an XML data, but the data is useless because of the xml tag names.
PHP Code for Controller:
use JMS\Serializer\Annotation;
....
....
....
/**
* Version
* @return Response
*
* @Annotation\XmlKeyValuePairs
*
* @ApiDoc(
* resource=true,
* description="Method for API Version",
* statusCodes={
* 200="Success"
* },
* parameters={
* }
* )
*/
public function versionAction () {
$response = [
'code' => 200,
'message' => 'api version',
'data' => [
'version' => '0.0.1',
'lastupdate' => '2015-11-21 23:29:00',
'now' => (new \DateTime())->format('Y-m-d H:i:s')
]
];
return $response;
}
XML Output:
<?xml version="1.0" encoding="UTF-8"?>
<result>
<entry>200</entry>
<entry><![CDATA[api version]]></entry>
<entry>
<entry><![CDATA[0.0.1]]></entry>
<entry><![CDATA[2015-11-21 23:29:00]]></entry>
<entry><![CDATA[2015-11-22 00:41:30]]></entry>
</entry>
</result>
The problem here is the XML tags are all "entry". What I want is like this:
<?xml version="1.0" encoding="UTF-8"?>
<result>
<code>200</code>
<message>api version</message>
<data>
<version>0.0.1></version>
<lastupdate>2015-11-21 23:29:00</lastupdate>
<now>2015-11-22 00:41:30</now>
</data>
</result>
I'm using @Annotation\XmlKeyValuePairs
as documentation says, but couldn't get the result I want. There is a fix for that on here and it's working, but it's not a good solution because the file is from composer.
I dont know if I'm missing something or it's a bug in JMSSerializerBundle, or Symfony2 or do I have to use another annotation to get XmlKeyValuePairs working?