将协议缓冲区转换为 POJO [英] Converting a Protocol Buffer to a POJO

查看:38
本文介绍了将协议缓冲区转换为 POJO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可以将 Protobuff 对象映射到 POJO 的工具或库.我想让 pojo 实现我无法使用 ProtoBuff 对象的其他接口.还是我必须手动进行此转换?

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?

推荐答案

可能来不及了,不过你可以试试 protobuf 转换器 库.它很容易使用.

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

将 POJO 对象转换为相关的 protobuf 消息:

Convert POJO object to related protobuf message:

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

反向转换代码:

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

这篇关于将协议缓冲区转换为 POJO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆