RegistrationDateAdapter extends XmlAdapter<String, XMLGregorianCalendar> { @Override public String marshal(XMLGregorianCalendar xmlGregorianCalendar) throws Exception { try { return xmlGregorianCalendar.toXMLFormat(); } catch (Exception e) { throw new Exception("Error marshaling response.", e); } }  @Override XMLGregorianCalendar unmarshal(String datetime); @Override String marshal(XMLGregorianCalendar xmlGregorianCalendar);  }
@Test public void marshalTest() throws Exception { XMLGregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(); calendar.setYear(2020); calendar.setMonth(2); calendar.setDay(1); calendar.setHour(2); calendar.setMinute(59); calendar.setSecond(0); String calendarStringRepresentation = calendar.toXMLFormat(); RegistrationDateAdapter adapter = new RegistrationDateAdapter(); assertEquals(calendarStringRepresentation, adapter.marshal(calendar)); }