編集#1:JAXB RI 2.2.6(本日12/06/12現在)を使用しましたが、同じ動作が見られます:-(
XMLペイロードのマーシャリングを解除するためにJAXBを使用しています。Unmarshallerを介して初めて無効なペイロードを渡すと、次のタイプのエラーが発生します。
javax.xml.bind.UnmarshalException: Unable to create an instance of foo.bar.FooBarType
- with linked exception:
[java.lang.InstantiationException]
コードの次の行(catch()ブロック内)で、同じUnmarshallerインスタンスを試し、有効なペイロードを指定します。次のタイプのエラーが発生します。
java.lang.ClassCastException: foo.bar.SomeAType cannot be cast to foo.bar.SomeBType
次の行(これも後続のcatch()で)で、同じUnmarshallerインスタンスを試し、同じ有効なペイロードを再度与えます。これにより、正常にアンマーシャリングされます。
誰かがJAXBでこの種の動作を経験したことがありますか?ここでバグが発生していますか?どこを見たり掘ったりしますか?
これが私が使用しているJAXBjarのマニフェストの詳細です。
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 1.5.0_12-b04 (Sun Microsystems Inc.)
Specification-Title: Java Architecture for XML Binding
Specification-Version: 2.1
Specification-Vendor: Sun Microsystems, Inc.
Implementation-Title: JAXB Reference Implementation
Implementation-Version: 2.1.12
Implementation-Vendor: Sun Microsystems, Inc.
Implementation-Vendor-Id: com.sun
Extension-Name: com.sun.xml.bind
Build-Id: hudson-jaxb-ri-2.1-833
Class-Path: jaxb-api.jar activation.jar jsr173_1.0_api.jar jaxb1-impl.jar
Name: com.sun.xml.bind.v2.runtime
Implementation-Version: hudson-jaxb-ri-2.1-833
よろしくお願いします!
編集#2:すべてを貼り付けることはできませんが、それがどのように見えるかの要点は次のとおりです。
final JAXBContext jaxbContext = JAXBContext.newInstance(FooRequestType.class);
final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
JAXBElement<FooRequestType> result = null;
try {
//try unmarshalling invalid payload.
result = unmarshaller.unmarshal(invalidPayload.getDocumentElement(), FooRequestType.class);
}catch(Exception e1){
try {
//now try unmarshalling valid payload . ##NOTE: If you try unmarshalling Invalid Payload here, it will fail again.
result = unmarshaller.unmarshal(validPayload.getDocumentElement(), FooRequestType.class);
} catch(Exception e2){
//try again unmarshalling valid payload
result = unmarshaller.unmarshal(validPayload.getDocumentElement(), FooRequestType.class);
System.out.println("Result:=" + result.getValue());
System.out.println("Successfully unmarshalled. Exiting with (0)");
System.exit(0);
}
}
System.out.println("Not expecting to reach here.Exiting with (1)");
System.exit(1);
編集#3:JAXBImplとしてEclipseLinkMOXyを使用して、同じコードを実行しました。そしてそれは正しく動作します。Sun / Oracle JAXB RIでバグを開きました:http://java.net/jira/browse/JAXB-931