java - 将具有接口字段的类转换为 protobuf
问题描述
我有一个带有接口字段的类,并且该接口有多个实现。我需要将我的类转换为 protobuf,但我无法映射接口字段,这实际上是一个类型接口。这是我的类结构的Java代码:
class A {
String name;
String occupation;
Operable operable;
}
interface operable {
}
class OperableA implements operable {
String job;
List<String> tasks;
}
class OperableB implements operable {
int numberOfWorkers;
List<String> skills;
List<String> nameOfWorkers;
}
这个结构如何映射到 proto 文件中,请帮忙。
解决方案
您不能在 protobuf 中对类或接口继承建模,如此处所述
不过,不要去寻找类似于类继承的工具——协议缓冲区不会那样做。
推荐阅读
- c# - Unsafe.InitBlockUnaligned 的奇怪行为
- sitecore - 如何在 Sitecore 中自定义 UI 后防止出现错误消息
- python - python中的Cqlengine在模式更改后不会在新字段中插入值(Cassandra)
- javascript - 无法访问 for 循环中使用的链式 Promise 内的外部范围变量
- python - ListBuckets 操作:拒绝访问 - aws mfa 令牌
- typescript - 工作表 API (google apis) 返回错误“'无效授权:找不到帐户'
- python - 如何将 sql 查询转换为 Pandas Dataframe 和 PySpark Dataframe
- css - css网格两侧不寻常的空白
- inventory - Odoo 13:在过去的日期发布库存估价
- entity-framework-core - Azure 数据库在 localhost 上工作,但在与 azure 服务应用程序一起使用时不能