Problem to convert date to Brazilian standard using JAXB

Asked

Viewed 47 times

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 unmarshal won’t work, even if he’s called.

  • Adapter is called. I use the annotation @Xmljavatypeadapter(Dateadapter.class) above the variable.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.