Trying to use high source/jaxb2-annotate-plugin library to generate custom annotations on the generated classes from XSD but getting some errors. Need to generate the class with JsonView annotation but it fails to parse that annotation. The Jackson library is already in the path ( which supports/has JsonView) but still it fails. Unable to decipher what else could be wrong.
@lexicore - I believe you might be able to help as I see you are the developer of this library on Github. I did follow the docs on GitHub but couldn't figure out. Please advise if I am missing anything in setting up.
ERROR snippet:
[INFO] Sources are not up-to-date, XJC will be executed.
[ERROR] Error while generating code.Location [ file:/C:/dev/workspace/JSONVIEW/jsonViewModel/schema/src/main/resources/address.xsd{20,56}].
org.xml.sax.SAXParseException; systemId: file:/C:/dev/workspace/JSONVIEW/jsonViewModel/schema/src/main/resources/address.xsd; lineNumber: 20; columnNumber: 56; Error parsing annotation.
at org.jvnet.jaxb2_commons.plugin.annotate.AnnotatePlugin.annotate(AnnotatePlugin.java:460)
at org.jvnet.jaxb2_commons.plugin.annotate.AnnotatePlugin.annotate(AnnotatePlugin.java:418)
at org.jvnet.jaxb2_commons.plugin.annotate.AnnotatePlugin.processFieldOutline(AnnotatePlugin.java:200)
at org.jvnet.jaxb2_commons.plugin.annotate.AnnotatePlugin.processClassOutline(AnnotatePlugin.java:188)
at org.jvnet.jaxb2_commons.plugin.annotate.AnnotatePlugin.run(AnnotatePlugin.java:146)
Test_1.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="2.1"
xmlns:annox="http://annox.dev.java.net"
jaxb:extensionBindingPrefixes="annox">
<xsd:complexType name="TType">
<xsd:annotation>
<xsd:appinfo>
<annox:annotate>@java.lang.SuppressWarnings({"unchecked","rawtypes"})</annox:annotate>
<annox:annotate target="package">@javax.annotation.Generated({"XJC","JAXB2 Annotate Plugin"})</annox:annotate>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="TField" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<annox:annotate target="field">@com.fasterxml.jackson.annotation.JsonView(Views.Public.class)</annox:annotate>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
**POM.xml**
( showing dependency jars which support JsonView annotation and supporting classes ). http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 A View 0.0.1-SNAPSHOT
<artifactId>schema</artifactId>
<properties>
<xsd.build.dir>${basedir}/src/main/resources</xsd.build.dir>
<generated.source.location>${basedir}/target/generated-sources/src</generated.source.location>
</properties>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
</dependency>
<dependency>
<groupId>B</groupId>
<artifactId>View</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.12</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<generateDirectory>${generated.source.location}</generateDirectory>
<schemaDirectory>${xsd.build.dir}</schemaDirectory>
<addIfExistsToEpisodeSchemaBindings>true</addIfExistsToEpisodeSchemaBindings>
<extension>true</extension>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>1.0.2</version>
</plugin>
</plugins>
<args>
<arg>-Xannotate</arg>
</args>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
<execution>
<id>attach-sources</id>
<phase>DISABLE_FORKED_LIFECYCLE_MSOURCES-13</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Note: Jackson-annotations-2.8.3 jar is in the classpath which has JsonView class.
You apparently have a problem with this annotation:
There may be two reasons:
You have to make
Views.Public.classfully-qualified class name.You have to include the dependency as
plugininmaven-jaxb2-plugin, like this:Include all you dependencies.
If nothing helps, send me a PR with MCVE here: https://github.com/highsource/jaxb2-annotate-plugin-support
Update
I've checked your test project:
I got the following error:
What this says is that
baseModel.Views.Internal.classcannot be parsed as an array ofClasses.Chaning your customization to:
Solves the problem.
Two remarks.
jaxb2-annotate-plugin-supportfor future reference and help for other users.