多数の応答を返す Java spring ベースの Web サービスがあります。多くのフィールドが常に利用可能であり、サービスを呼び出した結果が JAXB 応答の「ペイロード」要素に配置されるという点で汎用的な応答を設計したいと考えています。これを行うために、次の応答タイプの定義を思いつきました。
<xs:element name="serviceResponse">
<xs:element name="responseStatus" type="xs:int"/>
<xs:element name="errorNumber" type="xs:int"/>
<xs:element name="errorDescription" type="xs:string"/>
<xs:element name="payLoad" type="?????"/>
</xs:element>
その要素のタイプがサービスのタイプによって異なる場合、payLoad 要素を宣言するにはどうすればよいですか。各サービスは、「PayloadElement」に追加したい異なる JAXB タイプを生成します。たとえば、ここに私が期待する応答の例をいくつか示します。
顧客リスト:
<serviceResponse>
<responseStatus>0</responsesStatus>
<errorNumber>0</errorNumber>
<errorDescription>null</errorDescription>
<payLoad>
<customers>
<customer>
<customerId>2323</customer>
<customerName>Joe Bloggs</customerName>
<invoiceNumber>90347347</invoiceNumber>
</customer>
<customer>
<customerId>54</customer>
<customerName>Dave hewitt</customerName>
<invoiceNumber>342343</invoiceNumber>
</customer>
</customers>
</payLoad>
</serviceResponse>
注文一覧
<serviceResponse>
<responseStatus>0</responsesStatus>
<errorNumber>0</errorNumber>
<errorDescription>null</errorDescription>
<payLoad>
<orders>
<order>
<orderId>567</orderId>
<ProductList>
<product>
<productId>234324</product>
<Quantity>5</Quantity>
</product>
<product>
<productId>23434</product>
<Quantity>7</Quantity>
</product>
</ProductList>
</order>
<order>
<orderId>34232</orderId>
<ProductList>
<product>
<productId>1231</product>
<Quantity>5</Quantity>
</product>
</ProductList>
</order>
</orders>
</payLoad>
</serviceResponse>
ご覧のとおり、ペイロード要素には、多くのタイプのいずれかである xml ドキュメントを含めることができます。これを serviceResponse 要素定義で宣言するにはどうすればよいですか?
ありがとう