WebSphere で実行される Java Web サービス クライアントを作成しています。RAD Developer で新しい「Web サービス クライアント」プロジェクトを作成し、WSDL を指定して「トップダウン Java Bean」を指定すると、多数のファイルが自動生成されました。
操作の 1 つが「GetAddressData」です。RAD Developer は、「GetAddressData.java」と「GetAddressDataResonse.java」を自動生成し、どちらも「XmlRootElement」で注釈を付けました。
「GetAddressData」の引数の 1 つは「RequestData」です。これは、worklow、module、username、および id の 4 つの文字列で構成される単純なオブジェクトです。RAD Developer は、私のために「RequestData.java」も生成しました。
Q: 一度に 1 フィールドずつレコードをパックおよびアンパックする代わりに、生の XML を JAXB の「RequestData」オブジェクトに置き換える方法はありますか?
私はこのようなことを試しました:
private static String theXml =
"<requestOptions>\n" +
" <WorkflowName>unmarshalTestWorkflow</WorkflowName>\n" +
" <ModuleName>unmarshalTestModule</ModuleName>\n" +
" <UserName>unmarshalTestName</UserName>\n" +
" <TransactionId>0099</TransactionId>\n" +
"</requestOptions>\n";
private RequestOptions mkRequestOptions () throws Exception {
JAXBContext context = JAXBContext.newInstance(RequestOptions.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
Object obj = unmarshaller.unmarshal(new StringReader (theXml));
RequestOptions requestOptions = (RequestOptions)obj;
...
しかし、私は取得し続けます:
error: Unexpected element "requestOptions". Expected elements are "".
どんな助けでも大歓迎です!前もって感謝します。