@XmlJavaTypeAdapter annotation on JAXB class doesn't work for JAX-RS application in EAP 6
Issue
- I have a JAX-RS application and am trying to utilise JAXB-JSON marshaling.
- This is my JAXB class definition:
@XmlRootElement(name = "myData")
public class MyData {
private Date timestamp;
public MyData() {}
@XmlJavaTypeAdapter(value=JaxbDateAdapter.class, type=Date.class)
@XmlElement(name = "timestamp")
public Date getTimestamp() { return timestamp; }
public void setTimestamp(Date timestamp) { this.timestamp = timestamp; }
}
- And this is my
JaxbDateAdapterdefinition:
import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.text.SimpleDateFormat;
import java.text.ParsePosition;
import java.util.Date;
public class JaxbDateAdapter extends XmlAdapter<String, Date> {
@Override
public String marshal(Date date) throws Exception {
return new SimpleDateFormat("yyyy-dd-MM HH:mm:ss z").format(date);
}
@Override
public Date unmarshal(String string) throws Exception {
return new SimpleDateFormat("yyyy-dd-MM HH:mm:ss z").parse(string, new ParsePosition(0));
}
}
- However, this XML adapter doesn't seem to work and the date returned is still in millis. Do you have any idea why this may be so?
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 6
- RESTEasy
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.