JAX-WS を使用して Web サービスを呼び出しています。コンテンツを Java オブジェクトに変換したい。
以下は、Web サービス応答のコンテンツ部分です。
<header xmlns="">
<store>
<store_id>1</store_id>
<store_name>ACME</store_name>
</store>
</header>
次に、次のようにクラスを作成しました。
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"store_id",
"store_name" })
@XmlRootElement(name = "store")
static public class store {
@XmlElement(name = "store_id", required = true)
protected String store_id;
@XmlElement(name = "store_name", required = true)
protected String store_name;
}
私のJAXBコード:
List result = service.getService1Soap12().getDivisions().getContent();
ElementNSImpl e =(ElementNSImpl)result.get(0);
JAXBContext context = JAXBContext.newInstance(store.class);
Unmarshaller um = context.createUnmarshaller();
JAXBElement element = (JAXBElement) um.unmarshal(e);
store customer = (store) element.getValue();
次のエラーが表示されます。
Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"store"). Expected elements are <{http://tempuri.org/}header>
これを修正するために数え切れないほどのことを試しました。どんな助けでも素晴らしいでしょう!