加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

FOSRestBundle输出错误的xml

发布时间:2020-12-16 22:56:35 所属栏目:百科 来源:网络整理
导读:当我请求xml时,我的 XML输出看起来很奇怪. 控制器: use FOSRestBundleControllerAnnotations as REST;class RestController { /** * @RESTView */ public function getAgenciesAction() { return array("bb"=array('zz'='vv'),'zz'); }} 请求标题: ???
当我请求xml时,我的 XML输出看起来很奇怪.

控制器:

use FOSRestBundleControllerAnnotations as REST;
class RestController {
    /**
     * @RESTView
     */
    public function getAgenciesAction() {
      return array("bb"=>array('zz'=>'vv'),'zz');
    }
}

请求标题:
????Aceept:application / xml

响应:

<?xml version="1.0" encoding="UTF-8"?>
<result>
  <entry>
    <entry><![CDATA[vv]]></entry>
  </entry>
  <entry><![CDATA[zz]]></entry>
</result>

为什么只返回结束节点而不是所有键和值?

解决方法

FOSRestBundle中的xml序列化程序不使用密钥序列化数组.每个数组条目将作为< entry>结果在响应中,无论关键.示例中的输出是正确的.键仅在json输出中相关.

序列化实体具有正确的输出,因为该字段将导致< field>值< / field>

示例控制器

/**
 * @ApiDoc(
 *     description="Returns the own user details",*     statusCodes={
 *         200="Returned when successful",*         403="Returned when missing permissions",*     }
 * )
 *
 * @RestGet("/users/me")
 * @RestView(serializerGroups={"details"})
 */
public function getMeAction()
{
    $user = $this->getUser();

    return array('user' => $user);
}

和响应.您看,关键用户输出为< entry>.

<?xml version="1.0" encoding="UTF-8"?>
<result>
  <entry>
    <id><![CDATA[517781e2e707a00217000000]]></id>
    <username><![CDATA[admin]]></username>
    <email><![CDATA[admin@example.com]]></email>
    <company><![CDATA[acme]]></company>
  </entry>
</result>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读