Background
I have a Root element class which contains variable of the class java.sql.Timestamp
, I want JAXB to create xml element from that variable.
What I have tried
import java.sql.Date;
import java.sql.Timestamp;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class TimestampAdapter extends XmlAdapter <Date, Timestamp> {
public Date marshal(Timestamp v) { return new Date(v.getTime()); } public Timestamp unmarshal(Date v) { return new Timestamp(v.getTime()); }
}
@XmlJavaTypeAdapter(TimestampAdapter.class)
public java.sql.Timestamp getEndDate() {if (endDate == null)
retrieveInfo();
return endDate;
}
Problem
I still get this exception
java.sql.Date does not have a no-arg default constructor.
Also I have checked This Thread, but it is talking about String to TimeStamp, not my case.
Any help would be appreciated.
EDIT
This variable is in the class OrderStatus
, I call it from class OrderImpl
like this
@Override
@XmlElement(name = "Status", type = OrderStatus.class)
public OrderStatus getStatus() {
return status;
}
Your XmlAdapter
should convert the Timestamp
to/from java.util.Date
instead of java.sql.Date
.
Your adapter needs to be like this:
public class TimestampAdapter extends XmlAdapter<Date, Timestamp> {
public Date marshal(Timestamp v) {
return new Date(v.getTime());
}
public Timestamp unmarshal(Date v) {
return new Timestamp(v.getTime());
}
}
and
@XmlJavaTypeAdapter( TimestampAdapter.class)
public Timestamp done_date;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With