Thrift generated Java code generates loads of warnings

有些话、适合烂在心里 提交于 2019-12-12 06:52:09

问题


Our project uses several thrift-generated classes. The java code generated by these classes is generating several hundred warnings, most of them unused imports and not declaring a long serialVersionUID (from Comparable).

The rest of the codebase is... also generating warnings, to put it politely, and I don't want to just disable warnings of the type the thrift code is generating. Is there anything I can do with thrift to get it to generate better code? Is there a way to include warning suppression decoration in the generated code?

We're using thrift 0.9.1.


回答1:


An alternative to the standard Thrift Java implementation is Facebook Swift.

You can use the the Swift Generator tool included with that software to generate annotated Java classes from your IDL which are much cleaner, and I'm pretty sure they have an option for modifying the templates as well.

If you don't want to use their included "Nifty" server, and integrate instead with the standard Thrift transports, you can use the NiftyProcessorAdapters utility class to create a TProcessor:

ThriftCodecManager codecManager = new ThriftCodecManager(
    new CompilerThriftCodecFactory(false)
);
List<ThriftEventHandler> eventList = Collections.emptyList();
ThriftServiceProcessor proc = new ThriftServiceProcessor(codecManager, eventList, svc);
this.multiplex.registerProcessor(name, NiftyProcessorAdapters.processorToTProcessor(proc));

The code that Swift generates is basically just POJOs, and should not be nearly as many warnings. That said the Swift runtime pulls in a bunch of dependencies and may not be suitable for all applications.



来源:https://stackoverflow.com/questions/26631900/thrift-generated-java-code-generates-loads-of-warnings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!