我在超类上使用 xjc:superClass 和 @javax.xml.bind.annotation.XmlTransient 注释。
我正在尝试切换到 Moxy,但出现此错误:
'Exception Description: Property [aspectStyleBlock] in class [com.aplia.q4.document.ValueStyle] references a class [com.aplia.q4.domain.AbstractBlock] that is marked transient, which is not allowed.
- with linked exception:
[Exception [EclipseLink-50057] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.JAXBException
' .
这一切在 jaxb 2.1 下都可以正常工作
如果我删除超类上的 XmlTransient 注释,则会收到此错误:
'ava.lang.RuntimeException: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.NullPointerException]
....
'Caused by: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.NullPointerException]
at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:825)
at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:136)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:142)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:129)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:93)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:202)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:331)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
at com.aplia.q4.service.hosting.impl.JAXBAdapter.<init>(JAXBAdapter.java:35)
... 27 more
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.generateChoiceCollectionMapping(MappingsGenerator.java:686)
at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.generateMapping(MappingsGenerator.java:434)
at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.generateMappings(MappingsGenerator.java:1996)
at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.generateMappings(MappingsGenerator.java:1957)
at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.generateProject(MappingsGenerator.java:193)
at org.eclipse.persistence.jaxb.compiler.Generator.generateProject(Generator.java:174)
at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:830)
at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:823)
... 41 more'
我有大约 100 个从模式生成的类(我不控制模式)。我尝试使用http://jaxb2-commons.dev.java.net/basic/inheritance来实现接口而不是 xjc:superclass,但它需要我列出所有 100 个类,因为绑定 xpath 可以t 在多个节点上匹配。不愿意这样做,除非这是解决问题的唯一方法。
这阻碍了我转换为 Moxy impl 的努力。
有关我的设置的详细信息以及我选择添加 XmlTransient 注释的原因:
来自https://sites.google.com/site/codingkb/java-2/jaxb/jaxb-4
" 导致在派生另一个类的类上不允许使用 @XmlValue 您希望自动生成的 JAXB 类扩展一个公共父类...所以您将这样的内容添加到您的 XSD:
不幸的是,当您进行编译时,您会收到一条错误消息:线程“main”com.sun.xml.bind.v2.runtime.IllegalAnnotationsException 中的异常:IllegalAnnotationExceptions @XmlValue 的计数在派生另一个类的类上是不允许的.
解决方法是在基类中添加注解:@javax.xml.bind.annotation.XmlTransient public class JAXBSuperClass { ... }"
我的 pom 文件(仅相关部分):
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1.13</version>
<scope>runtime</scope>
</dependency>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.7.4</version>
<executions>
<execution>
<id>generate-q4-document-jaxb</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<extension>true</extension>
<args>
<arg>-Xboolean-getter</arg>
<arg>-Xinheritance</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.5.3</version>
</plugin>
<plugin>
<groupId>com.nebulent.xjc</groupId>
<artifactId>boolean-getter</artifactId>
<version>1.0</version>
</plugin>
</plugins>
<schemaDirectory>${project.build.directory}/generated-sources/schema</schemaDirectory>
<bindingDirectory>${basedir}/src/main/resources/jaxb-bindings</bindingDirectory>
<forceRegenerate>true</forceRegenerate>
</configuration>
</execution>
</executions>
</plugin>
让我知道您是否需要架构或任何其他信息。
提前致谢!