I'm using Spring 3 to create some ReST services. When POSTing XML, Spring handles String fields but won't convert Date fields. Here is an example:
@XmlRootElement(name = "TestObj")
@XmlAccessorType(XmlAccessType.FIELD)
public class TestObj {
@XmlElement(type = Date.class, name = "Birthdate")
@XmlJavaTypeAdapter(BirthdateXmlAdapter.class)
private Date birthdate;
@XmlElement(type = String.class, name = "Name")
private String name;
// getters and setters ...
}
I thought perhaps an XmlAdapter is required and created one to marshall/unmarshall according to the date format I need. BirthdateXmlAdapter is called but a null value is passed in which of course sets the birthdate field to null.
@RequestMapping(value="/test", method=RequestMethod.POST)
public TestObj test(@RequestBody TestObj testObj) {
logger.debug(testObj.toString());
return testObj;
}
Pretty simple use case here. I use RestClient to POST XML and see the "name" attribute set properly in my TestObj but birthdate is null.