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