ZonedDateTimeXmlAdapter extends XmlAdapter<String, ZonedDateTime> { @Override public String marshal(ZonedDateTime zonedDateTime) { if (null == zonedDateTime) { return null; } return zonedDateTime.withZoneSameInstant(ZoneOffset.UTC).format(formatter); }  @Override ZonedDateTime unmarshal(String s); @Override String marshal(ZonedDateTime zonedDateTime);  }
@Test public void testMarshal() { ZonedDateTimeXmlAdapter adapter = new ZonedDateTimeXmlAdapter(); String marshalled = adapter.marshal(ZonedDateTime.of(2015, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC)); assertEquals("2015-01-01T00:00:00Z", marshalled); marshalled = adapter.marshal(ZonedDateTime.of(2015, 1, 1, 1, 0, 0, 0, ZoneId.of("Europe/Berlin"))); assertEquals("2015-01-01T00:00:00Z", marshalled); }