1


スーパークラスで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
' . 

これはすべてjaxb2.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あります(スキーマを制御していません)。xjc:superclassの代わりにインターフェースを実装するためにhttp://jaxb2-commons.dev.java.net/basic/inheritanceを使用しようとしましたが、バインディングxpathができるので、100個のクラスすべてをリストする必要があります。 t複数のノードで一致します。それが問題を解決する唯一の方法でない限り、そうすることには消極的です。

これは、Moxyimplに変換する私の努力を妨げています。

セットアップの詳細と、XmlTransientアノテーションを追加することを選択した理由:

https://sites.google.com/site/codingkb/java-2/jaxb/jaxb-4から

"原因@XmlValueは、別のクラスを派生させるクラスでは許可されません。自動生成されたJAXBクラスで共通の親クラスを拡張する必要があります...したがって、XSDに次のようなものを追加します。

残念ながら、コンパイルに行くと、エラーメッセージが表示されます。スレッド "main"の例外com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:1カウントの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>

スキーマやその他の情報が必要な場合はお知らせください。

前もって感謝します!

4

1 に答える 1

0

注: 私はEclipseLink JAXB(MOXy)のリーダーであり、JAXB(JSR-222)エキスパートグループのメンバーです。

あなたの質問に関連するいくつかの問題があります:


問題#1-MOXy例外

発生している問題を示す小さなサンプルを提供していただけますか?

更新1: 発生している問題は、次のEclipseLinkバグに関連していると思います。

更新2: EclipseLink 2.3.3(5月10日ダウンロード可能)および2.4.0(5月11日ダウンロード可能)ストリームの両方のバグを修正しました。これらは次の場所からダウンロードします。


問題#2-サブクラスの@XmlValue

JAXB RIは、このユースケースを処理できません。

Exception in thread "main" com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
@XmlValue is not allowed on a class that derives another class.
    this problem is related to the following location:
        at public java.lang.String forum10437666.Child.getValue()
        at forum10437666.Child

    at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:472)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:302)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1140)
    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154)
    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:121)
    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:363)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
    at forum10437666.ValueDemo.main(ValueDemo.java:11)

EclipseLink JAXB(MOXy)は、親クラスがそのフィールド/プロパティをXML要素にマップしない限り可能です。

親クラスには、XML属性へのマッピングのみが含まれます。

package forum10437666;

import javax.xml.bind.annotation.XmlAttribute;

public class Parent {

    private int id;

    @XmlAttribute
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

}

Child拡張Parentし、でマップされたプロパティを持ち@XmlValueます。

package forum10437666;

import javax.xml.bind.annotation.XmlValue;

public class Child extends Parent {

    private String value;

    @XmlValue
    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

}

ValueDemo

package forum10437666;

import javax.xml.bind.*;
import javax.xml.namespace.QName;

public class ValueDemo {

    public static void main(String[] args) throws Exception {
        JAXBContext jc = JAXBContext.newInstance(Child.class);

        Child child = new Child();
        child.setId(123);
        child.setValue("ABC");

        JAXBElement<Child> je = new JAXBElement<Child>(new QName("child"), Child.class, child);
        Marshaller marshaller = jc.createMarshaller();
        marshaller.marshal(je, System.out);
    }

}

出力

<?xml version="1.0" encoding="UTF-8"?>
<child xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="123">ABC</child>
于 2012-05-03T20:11:59.880 に答える