I want to set up date sorting in JAXB. This is a variant of this already asked question . I would think that I would use the XMLAdapter as indicated by this answer .
But I canโt do it exactly, because I go the other way, generating JAXB beans from .XSD - I canโt add annotations to JAXB beans because they are generated code.
I tried calling Marshaller.setAdapter () but no luck.
final Marshaller marshaller = getJaxbContext().createMarshaller(); marshaller.setSchema(kniSchema); marshaller.setAdapter(new DateAdapter()); ... private static class DateAdapter extends XmlAdapter<String, XMLGregorianCalendar> { @Override public String marshal(XMLGregorianCalendar v) throws Exception { return "hello";
If the relevant part of my generated JAXB bean is as follows:
@XmlSchemaType(name = "date") protected XMLGregorianCalendar activeSince;
When I do this, what happens by default is date / XMLGregorianCalendar marshalling. As if I didnโt do it.
Any help is appreciated.
Thanks,
Charles
jaxb
Charles O.
source share