Jax与Ri实施

时间:2015-10-27 20:13:40

标签: java xml web-services jaxb wsdl

我有返回List的SEI接口

    public ArrayList<Passenger> bookTicket(String[] name)

但问题是wsdl需要Array.In JaxB XmlAdapter将ArrayList转换为Passenger数组。

public class ArrayListAdapter extends XmlAdapter<Passenger[], ArrayList<Passenger>>{
public ArrayList<Passenger> unmarshal(Passenger[] passengers) throws Exception {

    ArrayList list=new ArrayList<Passenger>();
    for(Passenger passenger:passengers){
        list.add(passenger);
    }
    return list;
public Passenger[] marshal(ArrayList<Passenger> passengerList) throws Exception {
    System.out.println("---------------222222222222222");
    Passenger []passengers=new Passenger[passengerList.size()];
    int i=0;
    for(Object passenger:passengerList){
        passengers[i++]=(Passenger)passenger;
    }
    return passengers;
}
}
}

但是它给了我Class Cast Exception,在返回ArrayList时无法强制转换为Passenger。

通过JaxB Class ---

@XmlRootElement(name = "bookTicketResponse", namespace = "http://irctc.org/reservationsi/wsdl")

@XmlAccessorType(AccessType.FIELD) @XmlType(name =&#34; bookTicketResponse&#34;,namespace =&#34; http://irctc.org/reservationsi/wsdl&#34;) 公共课BookTicketResponse {

@XmlElement(name = "return", namespace = "http://irctc.org/reservationsi/types")
@XmlJavaTypeAdapter(value=ArrayListAdapter.class)
private ArrayList _return;

/**
 * 
 * @return
 *     returns ArrayList
 */
public ArrayList get_return() {
    return this._return;
}

/**
 * 
 * @param _return
 *     the value for the _return property
 */
public void set_return(ArrayList _return) {
    this._return = _return;
}

}

请帮帮我,为什么我要获得类Cast异常bcoz JaxB提供XmlJavaTypeAdapter将CollectionType转换为Array.I使用wsgen工具生成JaxB类

0 个答案:

没有答案