jsonrestcxfauto-generatewadl

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.

Now swagger can do it without a problem, but I would prefer to use cxf-wadl2java maven plugin. By default it doesn't expect the json format. See the exception cause stack trace below.

Is there a way to configure the cxf-wadl2java plugin to read json document?

Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{' (code 123) in prolog; 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


Solution

  • May be you can have two step conversion. swagger.json to wadl file and then use wadl2java plugin.

    1. Install npm in you machine
    2. Use maven exec plugin and run command defined in this npm package to convert from swagger to wadl.
    3. Use cxf wadl2java plugin to generate java file from generated wadl file from above.

    EDIT

    There is a maven plugin provided by swagger.io. Please refer a usage example here