1
I’m having trouble converting xml to object using JAXB. The date comes in the format Sun Jan 30 16:08:23 BRT 18, and want to convert to Brazilian format 12-08-2009 16:08:23.
JAXB Conversion Class:
public class DateAdapter extends XmlAdapter<String, Date> {
Locale brasil = new Locale("pt", "BR");
private final SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss", brasil);
@Override
public String marshal(Date v) throws Exception {
return dateFormat.format(v);
}
@Override
public Date unmarshal(String v) throws Exception, ParseException {
return dateFormat.parse(v);
}
}
Is it error or the Adapter is not called? The date format in your date format is wrong too, in the
unmarshalwon’t work, even if he’s called.– Bruno César
Adapter is called. I use the annotation @Xmljavatypeadapter(Dateadapter.class) above the variable.
– Rafael Carlos