Reputation: 711
I have a xml tag in this format:
<DOB>19801213</DOB>
How can I unmarshal this xml tag into a Date variable?
@XmlElement (name = "DOB")
private Date dob
When I try to get dob it return me null.
Upvotes: 2
Views: 660
Reputation: 8272
You must use an XmlAdapter
import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class DateAdapter extends XmlAdapter<String, Date> {
@Override
public String marshal(Date v) throws Exception {
return .. ;
}
@Override
public Date unmarshal(String v) throws Exception {
return .. ;
}
}
and on your attribute you must add @XmlJavaTypeAdapter
@XmlJavaTypeAdapter(DateAdapter.class)
@XmlElement (name = "DOB")
private Date dob;
Upvotes: 2