序列化 GWT RPC 的 ANTLR 异常
我正在使用 GWT-RPC 调用 ANTLR 语法。 如果语法失败,我将创建一个包含语法抛出的错误/异常的对象并将其返回给客户端。
当我这样做时,我得到了异常:
com.google.gwt.user.client.rpc.SerializationException: Type 'org.antlr.runtime.NoViableAltException' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded.
我发现在 com.google.appengine.repackaged.org 中有一个相同的类,添加了一个公共无参数构造函数(GWT-RPC 序列化所需)。 antlr.runtime包。
如何将 org.antlr.runtime.NoViableAltException 转换为 com.google.appengine.repackaged.org.antlr.runtime.NoViableAltException?
I am using GWT-RPC to call an ANTLR grammar.
If the grammar fails, I create an object containing the errors/exceptions that were thrown by the grammar and return it to the client.
When I do this I get the exception:
com.google.gwt.user.client.rpc.SerializationException: Type 'org.antlr.runtime.NoViableAltException' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded.
I have found that there is an identical class with the addition of a public no argument constructor (needed for GWT-RPC serialization) in the com.google.appengine.repackaged.org.antlr.runtime package.
How do I convert the org.antlr.runtime.NoViableAltException into a com.google.appengine.repackaged.org.antlr.runtime.NoViableAltException?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要例外本身吗?我认为不需要 - 您可能需要消息或最多堆栈跟踪。由于无论如何您都要重新打包异常,因此只需重新打包所需的字符串并通过网络发送它们即可。
Do you need the exceptions themselves? I'd think not - you probably need the message or at most the stack trace. Since you're repackaging the exceptions anyway, just repack the needed strings and send those over the wire.
作为创建可序列化的新异常的替代方法,我让我的解析器重写了 BaseRecognizer 中的 emitErrorMessage 方法。
正如塔索斯在他的回答中所建议的那样,我实际上并不需要例外,只需要其中的消息。
As an alternative for creating new Exceptions that can be serialized, I have made my Parser override the emitErrorMessage method from BaseRecognizer.
As Tassos suggested in his answer, I did not actually need the exception, just the message from it.