JMS序列化器-对象属性的鉴别器

问题描述

我需要一个用于在引用对象的类属性中使用的类的鉴别符。这些对象的实现可能有所不同,并且正在实现相同的接口。

我的班级结构:

build.db

我的Yaml配置

class Product {
    private $detail; // instance of My\ProductDetail
}

abstract class My\ProductDetail {}

class My\ProductDetailImplA extends My\ProductDetail {
    private $type = 'a';
}

class My\ProductDetailImplB extends My\ProductDetail {
    private $type = 'b';
}

这就是我要做的:

My\Product:
    exclusion_policy: ALL
    properties:
      detail:
        type: My\ProductDetail # that is an interface
        expose: true

My\ProductDetail:
    exclusion_policy: ALL
    discriminator:
      field_name: type
      map:
        a: My\ProductDetailImplA
        b: My\ProductDetailImplB
        
My\ProductDetailImplA:
    exclusion_policy: ALL

My\ProductDetailImplB:
    exclusion_policy: ALL

不幸的是,反序列化无法按预期进行。抛出了Doctrine \ Instantiator \ Exception \ InvalidArgumentException “提供的类“ My \ ProductDetail”是抽象的,无法实例化”

那是因为元数据引用的是接口而不是类。

对于类属性,该功能是否尚未实现?还是我做错了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...