简体   繁体   English

使用json作为cxf-wadl2java的源

[英]Using json as a source for cxf-wadl2java

I received a specification of a RESTful service in json format and need to create a java api library for the client. 我收到了json格式的RESTful服务规范,需要为客户端创建Java api库。

Now swagger can do it without a problem, but I would prefer to use cxf-wadl2java maven plugin. 现在swagger可以毫无问题地做到这一点,但是我更愿意使用cxf-wadl2java maven插件。 By default it doesn't expect the json format. 默认情况下,它不希望使用json格式。 See the exception cause stack trace below. 请参阅下面的异常原因堆栈跟踪。

Is there a way to configure the cxf-wadl2java plugin to read json document? 有没有一种方法可以将cxf-wadl2java插件配置为读取json文档?

Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{' (code 123) in prolog; 由以下原因引起:com.ctc.wstx.exc.WstxUnexpectedCharException:序言中出现意外字符'{'(代码123); expected '<' at [row,col {unknown-source}]: [1,1] at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:653) at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2133) at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1181) at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1367) at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1261) at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1189) at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1178) at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1168) at org.apache.cxf.tools.wadlto.jaxrs.SourceGenerator.readXmlDocument(SourceGenerator.java:1757) ... 32 more [row,col {unknown-source}]的预期'<':com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:653)的com.ctc.wstx.sr.BasicStreamReader的[1,1] org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1367)的com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1181)的.nextFromProlog(BasicStreamReader.java:2133) org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1189)处的apache.cxf.staxutils.StaxUtils.java:1261)org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.read(StaxUtils.java:1189) org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1168)的java:1178)org.apache.cxf.tools.wadlto.jaxrs.SourceGenerator.readXmlDocument(SourceGenerator.java:1757)... 32更多

May be you can have two step conversion. 可能您可以进行两步转换。 swagger.json to wadl file and then use wadl2java plugin. 将swagger.json转换为wadl文件,然后使用wadl2java插件。

  1. Install npm in you machine 在机器上安装npm
  2. Use maven exec plugin and run command defined in this npm package to convert from swagger to wadl. 使用maven exec插件并运行此npm软件包中定义的命令,将swagger转换为wadl。
  3. Use cxf wadl2java plugin to generate java file from generated wadl file from above. 使用cxf wadl2java插件从上面生成的wadl文件生成Java文件。

EDIT 编辑

There is a maven plugin provided by swagger.io. swagger.io提供了一个maven插件。 Please refer a usage example here 在这里参考用法示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM