【问题标题】:jms serializer groups not working in child entitiesjms 序列化程序组在子实体中不起作用
【发布时间】:2019-08-08 08:33:08
【问题描述】:

jms 序列化程序组在子实体中不起作用

class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function __construct()
    {
        parent::__construct();
        // your own logic
    }

   /**
     * @var string
     *
     * @ORM\Column(name="first_name", type="string", length=255, nullable=false)
     * @Groups({"public"})
     * @Expose
     */
    private $firstName;

    /**
     * @var string
     *
     * @ORM\Column(name="last_name", type="string", length=255, nullable=false)
     * @Groups({"public"})
     * @Expose
     */
    private $lastName;

    /**
     * @ORM\OneToMany(targetEntity="SkUserCategory", mappedBy="user")
     * @Groups({"public"})
     * @Expose
     */
    private $categories;
}


class SkUserCategory
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     * @Expose
     */
    private $id;


    /**
     * @var \AppBundle\Entity\SkCategory
     *
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\SkCategory", inversedBy="categories")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="category_id", referencedColumnName="id", nullable=false)
     * })
     * @Groups({"public"})
     */
    private $category;

    /**
     * @var User
     *
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="categories")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
     * })
     */
    private $user;
}

在获取序列化组设置为 "public" 的用户详细信息时,我没有获取类别数据

【问题讨论】:

    标签: symfony doctrine jms serialization


    【解决方案1】:

    您必须使用注释@Groups({"public"}) 在SkCategory 实体中配置要在序列化过程中保留的字段以及

    【讨论】:

    • thankyou.. 排除政策和组概念是否矛盾...?
    猜你喜欢
    • 1970-01-01
    • 2017-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-06
    • 1970-01-01
    相关资源
    最近更新 更多