我可以在protobuf文件中使用java类吗?
我有两个java类,分别称为我可以在protobuf文件中使用java类吗?,java,protocol-buffers,micronaut,protobuf-java,Java,Protocol Buffers,Micronaut,Protobuf Java,我有两个java类,分别称为MyJavaClass和MyAnotherJavaClass MyJavaClass: @Data @Builder @AllArgsConstructor @NoArgsConstructor public class MyJavaClass implements Serializable { private Integer id; private String name; private MyAnotherJavaClass
MyJavaClass
和MyAnotherJavaClass
MyJavaClass:
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MyJavaClass implements Serializable {
private Integer id;
private String name;
private MyAnotherJavaClass myAnotherJavaClass;
}
MyAnotherJavaClass:
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MyAnotherJavaClass implements Serializable {
private Integer id;
private String someField;
}
我可以要这样的吗
message MyClassMessage {
MyJavaClass javaclass = 1;
}
因为我使用的是相同的字段,所以没有创建使用protobuf的消息。我认为消息中不能有类。您可能应该创建相应的消息。基本上,类可以有状态,也可以不容易序列化(即使您的特定示例是),因此不支持向proto添加类。另外,请注意protobuf实际上是面向跨语言代码生成的。如果它允许包含任意Java类作为字段,您将无法使用来自另一种语言的消息定义。