### Question:
DefaultHtmlSerializer implements HtmlSerializer { public String serialize(Document doc) { try { StringWriter sw = HtmlSerialization.createWriter(doc); if (doc.getDoctype() != null) { outputDocType(doc.getDoctype(), sw); } this.serialize(doc, sw); return sw.toString(); } catch (IOException ioe) { return null; } }  String serialize(Document doc); void serialize(Node n, Appendable output);  }### Answer:
@Test public void testComments() throws Exception { Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); doc.appendChild(doc.createElement("ABC")); doc.appendChild(doc.createComment("XYZ")); DefaultHtmlSerializer serializer = new DefaultHtmlSerializer(); assertEquals("Comment is preserved", "<ABC></ABC><!--XYZ-->", serializer.serialize(doc)); }