Converting a Protocol Buffer to a POJO

a 夏天 提交于 2019-12-19 03:15:10

问题


Is there a tool or library that can map a Protobuff object to a POJO. I would like to have the pojo implement other interfaces that I can not with the ProtoBuff object. Or would I have to manually do this conversion?


回答1:


Maybe too late, but you can try protobuf-converter library. It is easy to use.

Convert POJO object to related protobuf message:

POJOClass pojoInstance = new POJOClass();
...
ProtobufClass protoInstance = Converter.create().toProtobuf(ProtobufClass.class, pojoInstance );

Code for backward conversion:

POJOClass pojoInstance = Converter.create().toDomain(POJOClass.class, protoInstance);



回答2:


Take a look at ProtoStuff. I think it will do what you want.

I believe that you will want to use the "java-bean" compiler.

Edit: Changed the link.



来源:https://stackoverflow.com/questions/18261372/converting-a-protocol-buffer-to-a-pojo

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