从现有 Java 对象或 xsd 生成 .proto 文件 [英] Generating .proto file from existing Java objects or xsd

查看:80
本文介绍了从现有 Java 对象或 xsd 生成 .proto 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道可以生成 .proto 文件的任何工具?是来自现有的 xsd 还是来自现有的 Java 对象?

Does anyone know of any tools that will generate a .proto file? Either from an existing xsd or from existing Java objects?

我正在使用 Apache CXF 进行网络服务调用.返回的对象是从 xsd 自动生成的.

I am using Apache CXF to make a web service call. The returned object has been auto generated from an xsd.

好的,所以我现在想使用协议缓冲区将此数据传递到另一个系统.对象模型非常复杂并且会定期更改 - 即每次对象模型更改时我都会得到一个新的 xsd.我希望能够自动生成一个 .proto 文件,以便我可以使用谷歌协议缓冲区发送数据.

ok so I now want to pass this data using protocol buffers to another system. The object model is very complex and changes regularly - i.e. I get a new xsd every time the object model has changed. I would like to be able to auto generate a .proto file so that I can send data using google protocol buffers.

我到处找,但都卡住了.

I have been looking everywhere but have come stuck.

我很高兴

i.) 从 xsd 生成 .proto 文件或者ii.) 从 Java 对象(已从 xsd 生成)生成 .proto 文件

i.) generate .proto file from the xsd or ii.) generate .proto file from the Java objects (which have been generated from the xsd)

除了自己写一些东西之外,我找不到任何方法来做这件事......非常感谢您的帮助

I cannot find any way of doing this already short of writing something myself... Your help much appreciated

推荐答案

尝试 protostuff-runtime-proto 来自 Github 的项目.如果您有 protostuff RuntimeSchema,则可以通过以下代码将其转换为 .proto 文件:

Try protostuff-runtime-proto project from Github. If you have protostuff RuntimeSchema, you can convert it to the .proto file by this code:

System.out.println(Generators.newProtoGenerator(schema).generate()); 

这篇关于从现有 Java 对象或 xsd 生成 .proto 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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