java.sql.timestamp does not have a no-arg default constructor

今天做Webservice项目时,传递datatime类型的数据时,提示java.sql.timestamp does not have a no-arg default constructor~~~~

百度一下,好像是java.sql.Timestamp 无法和xml绑定。这个时候我们要写一个继承自XmlAdapter的adapter类,如下:

import java.sql.Timestamp;
import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class TimestampAdapter extends XmlAdapter {
public Date marshal(Timestamp t) {
return new Date(t.getTime());
}
public Timestamp unmarshal(Date d) {
return new Timestamp (d.getTime());
}
}

然后使用@XmlJavaTypeAdapter标记到使用java.sql.Timestamp类的地方,例如:

@XmlRootElement
public class InfoDTO {
private Timestamp createTime;
...
@XmlJavaTypeAdapter(TimestampAdapter.class)
public Timestamp getCreateTime() {
return this.createTime;
}
}

引用:http://alimama.iteye.com/blog/848895

你可能感兴趣的:(CXF,WebService)