以下のコードを使用しようとしていますが、値を取得できません。JAXBを使用していますが値を取得していません
main
{
String example="<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP:Body><ns0:findCustomerResponse xmlns:ns0=\"http://service.jaxws.blog/\"><return id=\"123\"><firstName>Jane</firstName><lastName>Doe</lastName></return></ns0:findCustomerResponse></SOAP:Body></SOAP:Envelope>";
ByteArrayInputStream bas=new ByteArrayInputStream(example.getBytes());
JAXBContext jc = JAXBContext.newInstance(Customer.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
SOAPMessage message = MessageFactory.newInstance().createMessage(null,
bas);
JAXBElement<Customer> jb = unmarshaller.unmarshal(message.getSOAPBody(), Customer.class);
Customer customer = jb.getValue();
System.out.println(customer.id);
System.out.println(customer.firstName);
System.out.println(customer.lastName);
}
@XmlAccessorType(XmlAccessType.FIELD)
public class Customer {
@XmlAttribute
int id;
String firstName;
String lastName;
}
@Andreasは、あなたがそれは、あなたが以下のように使用することができます取得したいので、もしお客様は、SOAPボディの深い2ネストされている、言ったように私は値
を得ました。また、firstNameとlastNameには@XmlElementを定義する必要があります。 – additionster
@additionsterいいえ、あなたはいません。 '@XmlAccessorType(XmlAccessType.FIELD)'アノテーションは、特に注釈がない限り、すべてのフィールドが暗黙的に '@ XmlElement'であることを意味し、JAXBはgetterとsetterを使用せずにフィールド値を直接読み書きします。 – Andreas
なぜ ''要素があなたの 'Customer'クラスに合っていると思いますか? 'id'属性は' '要素の上にあり、それは' ns0:findCustomerResponse>要素を挟んで2つ深くネストされています。 –
Andreas