问题
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