duanjuhuo8772 2017-12-16 03:24
浏览 64
已采纳

更改Symfony序列化中的序列化属性名称

I'm using Symfony serializer. It works well.

use Symfony\Component\Serializer\Annotation\Groups;

/**
 * 
 * @Groups({"default", "notification"})
 */
public function getUser()
{
    ...
}

Is it possible serialise property as another name? So I want to use getUser in framework, but property should named as profile in serialised json.

How I can do that?

  • 写回答

2条回答 默认 最新

  • douwen1313 2017-12-16 08:52
    关注

    Edit 19-11-2018, this feature is now available since Symfony 4.2:

    /**
     * @SerializedName("some_name")
     */
    private $lastName;
    

    More information in the doc.

    Thanks to Sodj for the reminder.


    You can use a custom name converter for that purpose. Every information to achieve this are in this part of the doc.

    There is also an issue opened to override property name of the serialized object directly with annotations https://github.com/symfony/symfony/issues/15171

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求给定范围的全体素数p的(p-2)的连乘积
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页