All you need to do is to define the JAXB objects to be Date as follows
@XmlElement(name = "CreditValueDate") @XmlJavaTypeAdapter(DateTypeAdapter.class) private Date creditValueDate; @XmlElement(name = "DebitValueDate") @XmlJavaTypeAdapter(DateTypeAdapter.class) private Date debitValueDate;
Class for DateTypeAdapters import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import javax.xml.bind.annotation.adapters.XmlAdapter; public class DateTypeAdapter extends XmlAdapter{ private SimpleDateFormat firstDateFormat = new SimpleDateFormat("yyyy-MM-dd"); private SimpleDateFormat secondDateFormat = new SimpleDateFormat("yyyy/MM/dd"); @Override public String marshal(Date v) { return secondDateFormat.format(v); } @Override public Date unmarshal(String v) throws ParseException { Date returnDate = null; try { returnDate = firstDateFormat.parse(v); } catch (Exception prse) { returnDate = secondDateFormat.parse(v); } return returnDate; } }
No comments :