You have some alternatives:
1- If you have an XML schema you can use JAXB validation with a custom MessageBodyReader
. See Validate JAXBElement in JPA/JAX-RS Web Service
2- You can use JAXB XMLAdapter
to customize how a data type is read and mapped to an object. See How do you specify the date format used when JAXB marshals xsd:dateTime?
You have to annotate the properties
@XmlRootElement
public class MyRequest{
@XmlElement(name = "mydate", required = true)
@XmlJavaTypeAdapter(DateAdapter.class)
protected Date mydate;
And define the XmlAdapter
public class DateAdapter extends XmlAdapter<String, Date> {
private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Override
public String marshal(Date v) throws Exception {
synchronized (dateFormat) {
return dateFormat.format(v);
}
}
@Override
public Date unmarshal(String v) throws Exception {
synchronized (dateFormat) {
return dateFormat.parse(v);
}
}
This solution is applicable to XML data and also to JSON using Jackson mapper because some of the JAXB annotations are supported deserializing data. See http://wiki.fasterxml.com/JacksonJAXBAnnotations
To configure jackson with jaxb provider in CXF see https://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-Jackson
<jaxrs:providers>
<bean class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider"/>
</jaxrs:providers>