ZonedDateTimeXmlAdapter extends XmlAdapter<String, ZonedDateTime> { @Override public ZonedDateTime unmarshal(String s) { if (null == s || s.isEmpty()) { return null; } return ZonedDateTime.parse(s, formatter); }  @Override ZonedDateTime unmarshal(String s); @Override String marshal(ZonedDateTime zonedDateTime);  }
@Test public void testUnmarshal() { ZonedDateTimeXmlAdapter adapter = new ZonedDateTimeXmlAdapter(); ZonedDateTime expected = ZonedDateTime.of(2015, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); ZonedDateTime unmarshalled = adapter.unmarshal("2015-01-01T00:00:00Z"); assertEquals(expected, unmarshalled); expected = ZonedDateTime.of(2015, 1, 1, 0, 0, 0, 0, ZoneId.of("Europe/Berlin")); unmarshalled = adapter.unmarshal("2015-01-01T00:00+01:00[Europe/Berlin]"); assertEquals(expected, unmarshalled); expected = ZonedDateTime.of(2015, 1, 1, 0, 0, 0, 0, ZoneId.of("+2")); unmarshalled = adapter.unmarshal("2015-01-01T00:00+02:00"); assertEquals(expected, unmarshalled); }