如何快速将Java / JSON转换为Xtext Langauge?
我正在开发一个处理传入 Json 的应用程序,我想轻松提取 json 数据并将其转换为我使用 Xtext 创建的 DSL 语言。我的目标是稍后能够将此数据转换为基于 my.data 的字符串。我可能可以提取数据并手动将其添加到一个大字符串变量中,但我想以编程方式执行此操作。那么,Xtext 支持吗?有什么方法可以将数据转换为 Xtext 对象,然后再转换为 String (我正在寻找类似 json 对象类的东西)
谢谢!
I am working on an app that processes incoming Json's and I want to easily extract the json data and convert it to a DSL language I'v created using Xtext. My goal is to be able to later convert this data to a String that is based on my. I could probably just extract the data and manually add it to a big String variable ,but I want to do this programmatically. So ,does Xtext supports that. Is there any way to convert data to an Xtext object and later to a String (I am looking for something like json object classes)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解你的问题,那么你已经创建了一个语法上“看起来像”JSON 的 Xtext 语法。
在这种情况下,Xtext 生成的解析器将能够解析遵循语法规范的文档(这意味着它们都是有效的 JSON,并且根据您的语言的语法也是有效的)。
您将编写的代码如下所示:
也就是说,Xtext 解析器可能完全是多余的,具体取决于您想要做什么,而像 Jackson 这样的解析器可能更适合。
If I correctly understand your question, you have already created an Xtext grammar that syntactically 'looks like' JSON.
In that case, the Xtext generated parser will be able to parse documents that follow the grammar specification (meaning they are both valid JSON and valid according to the grammar of your language).
The code that you would write looks as follows:
That being said, an Xtext parser might be complete overkill depending on what you are trying to do and something like Jackson might be a better fit.