【问题标题】:Convert class with interface field to protobuf将具有接口字段的类转换为 protobuf
【发布时间】:2020-07-24 07:19:21
【问题描述】:

我有一个带有接口字段的类,并且该接口有多个实现。我需要将我的类转换为 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文件中,请帮忙。

【问题讨论】:

    标签: java grpc grpc-java proto protobuf-java


    【解决方案1】:

    您不能在 protobuf 中对类或接口继承建模,如 here 所述

    不过,不要去寻找类似于类继承的工具 - 协议缓冲区不会这样做。

    【讨论】:

      猜你喜欢
      • 2013-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多