【问题标题】:How can I remove proxies field in symfony json如何删除 symfony json 中的代理字段
【发布时间】:2016-07-04 13:47:47
【问题描述】:

我想从返回的 json 中删除像 __initializer__: null,__cloner__: null, __isInitialized__: true, 这样的代理字段,但我不知道。

我不想使用* @Serializer\Exclude(),因为这些字段旁边还有一些字段。

这是一个示例 json:

emails: [
    {
        id: 1,
        subject: "Mrs. Astrid Wuckert",
        body: "Excepturi.",
        sendCopy: false,
        roles: [
            {
                __initializer__: null,
                __cloner__: null,
                __isInitialized__: true,
                name: "ROLE_ADMIN"
            },
            {
                name: "ROLE_RESELLER"
            },
            {
                name: "ROLE_RETAILER"
            },
            {
                name: "ROLE_CLUB_SHOP"
            }
        ]
    },
]

提前致谢。

【问题讨论】:

  • $em->detach($object); 是否删除代理字段?

标签: json symfony jms-serializer


【解决方案1】:

在创建规范器时尝试调用忽略字段:

$normalilzer->setIgnoredAttributes(["__initializer__", "__cloner__","__isInitialized__"]);

【讨论】:

  • $normalilzer 是什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-03
  • 1970-01-01
  • 2019-01-11
  • 2019-04-21
  • 2015-07-02
相关资源
最近更新 更多