Soap 処理には Apache Camel + JAXB を使用します。Java グラスは、cxf-codegen-plugin と呼ばれる Maven プラグインによって生成されます。
私が直面している問題は、リストであるプロパティを使用したいときです。その場合、正しいクラスのオブジェクトではなく、常に JAXBElement のリストを取得します。
この特定の xml が切り取られたとします。
<domainObjects avqxsi:type="avqsq:AssetAllocation" id="100" name="Some Name">
<nodes>101</nodes>
<nodes>102</nodes>
</domainObjects>
現在、すべての「ノード」は、タイプ の異なるドメイン オブジェクトの ID ですAANode
。したがって、xsd では次のように定義されます。
<xsd:complexType name="AssetAllocation">
<xsd:complexContent>
<xsd:extension base="avqsq:DomainObject">
<xsd:sequence>
<xsd:element ecore:reference="avqsq:AANode" maxOccurs="unbounded" name="nodes" type="xsd:IDREF"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
そして、いくつかの bindings.xml を定義しました:
<jaxb:bindings node="xsd:complexType[@name='AssetAllocation']//xsd:element[@name='nodes']">
<jaxb:property>
<jaxb:baseType name="my.api.xsd.AANode"/>
</jaxb:property>
</jaxb:bindings>
私が欲しいのは、次のような POJO プロパティです。
@XmlElementRef(name = "nodes")
protected List<AANode> nodes;
しかし、実行時に実際に得られるのはList<JAXBElement<AANode>>
、ClassCastException につながる です。
編集 1:JAXBElement.class
cxf-codegen フレームワークが、間違っていると思われる
プロパティに注釈が付けられていることを明確に確認できるクラスを生成しているという事実を見逃しました。興味深いことに、手動でアノテーションを AANode.class に変更すると、IllegalAnnotationException: AANode" で失敗するか、そのサブクラスのいずれもこのコンテキストに認識されません。
public class AssetAllocation
extends DomainObject
implements Serializable, Equals, HashCode, ToString
{
@XmlElementRef(name = "nodes", type = JAXBElement.class)
protected List<AANode> nodes;