I am developing RESTFul services in my application. We are using 'cxf-codegen-plugin' to generate the JAXB classes from the schema. For a given requirement, I need to add some annotation to the generated JAXB classes and I was trying to use Annotate Plugin(Annox) for this but having issue in using it. I am getting org.xml.sax.SAXParseException: Using "http://annox.dev.java.net" customizations requires the "-Xannotate" switch to enable this plug-in.
This is how I have the setup in my codebase: 1. The WSDL refer to a XSD where I have the definitions of annotations. 2. pom.xml is using 'cxf-codegen-plugin' to generate the jabx classes. 3. The RESTFul service need some additional annotation on the generated classes, so I am trying ti use Annox to get the work done.
This is the snippet from the XSD:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="gov.nih.nci.po.webservices.types"
xmlns:tns="gov.nih.nci.po.webservices.types" elementFormDefault="qualified"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.1"
xmlns:annox="http://annox.dev.java.net"
xmlns:ja="http://annox.dev.java.net/org.codehaus.jackson.annotate"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd
http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema.xsd"
jaxb:extensionBindingPrefixes="xjc annox">
<complexType name="PersonRole" abstract="true">
<annotation>
<appinfo>
<annox:annotate>
<ja:JsonTypeInfo use="CLASS" include="PROPERTY" property="@class"/>
</annox:annotate>
</appinfo>
</annotation>
<complexContent>
<extension base="tns:Role">
<sequence>
<element name="personId" type="long" />
</sequence>
</extension>
</complexContent>
</complexType>
</schema>
and this is how I want my generated class to look like:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "PersonRole", propOrder = { "personId" })
@XmlSeeAlso({ HealthCareProvider.class, OrganizationalContact.class,
ClinicalResearchStaff.class })
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class")
public abstract class PersonRole extends Role {
And below is the entry from pom.xml:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated-sources</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/PersonService.wsdl</wsdl>
<extraargs>
<extraarg>-xjc-Xannotate</extraarg> </extraargs>
</wsdlOption>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>${jackson.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</plugin>
Also I noticed that if I give some wrong value/configuration in xsd under JsonTypeInfo section, the build fail & complains (like mandatory field 'use' is missing etc) -- so I am assuming that the Annox plug-in is enabled & trying to do something. but then when I use above configurations, the build is failing with SAXParseException: Using "http://annox.dev.java.net" customizations requires the "-Xannotate" switch to enable this plug-in.
Could anybody please suggest as how this can be fixed?