是否有支持/扩展java.lang.Exception的protobuf消息?
我们正在尝试将CustomException表示为protobuf格式-是否有支持/扩展java.lang.Exception的protobuf消息?,exception,protocol-buffers,Exception,Protocol Buffers,我们正在尝试将CustomException表示为protobuf格式- public class CustomRestException extends RuntimeException { private CustomRestErrorMessage customRestErrorMessage; public CustomRestException (CustomRestErrorMessage customRestErrorMessage, Throwable cause) {
public class CustomRestException extends RuntimeException {
private CustomRestErrorMessage customRestErrorMessage;
public CustomRestException (CustomRestErrorMessage customRestErrorMessage, Throwable cause) {
super(cause);
this.customRestErrorMessage= customRestErrorMessage;
}
public CustomRestException (CustomRestErrorMessage customRestErrorMessage) {
this.customRestErrorMessage= customRestErrorMessage;
}
}
public class CustomRestErrorMessage implements Serializable {
private String causeMessage = "";
private String errorCode = "";
private String errorMessage = "";
private String errorSubCode = "";
private String stackTrace = "";
}
这是CustomRestExceptionProtos.proto文件
option java_package = "com.company.my.exception";
option java_outer_classname = "CustomRestExceptionProtos";
message CustomRestProtoException
{
required CustomRestProtoErrorMessage customRestErrorMessage = 1;
}
message CustomRestProtoErrorMessage
{
required string errorCode = 1;
required string errorMessage = 2;
required string errorSubCode = 3;
required string causeMessage = 4;
required string stackTrace= 5;
}
是否可以在.proto文件中将此CustomRestExceptionProtos表示为java.lang.Exception类型?如果我正确理解您的问题,您希望从CustomRestProtoException消息类型生成的java类从java.lang.Exception驱动。我认为实现这一点的唯一方法是编写插件来扩展java代码生成: 另一种更简单的方法是引入包装器Java异常子类来保存CustomRestProtoException对象:
public class CustomRestException extends Exception
{
private CustomRestProtoException exception;
// usual constructors etc.
}