### Question:
WadlDocumentToJson { public String convert(final Document doc) throws XMLStreamException { final JsonObjectBuilder builder = builderFactory.createObjectBuilder(); if (doc.getChildNodes().getLength() != 1) { return "{}"; } final Node item = doc.getChildNodes().item(0); return builder.add(item.getNodeName(), createNode(item)).build().toString(); }  String convert(final Document doc);  }### Answer:
@Test public void xmlToJson() throws Exception { final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new ByteArrayInputStream(("" + "<application xmlns=\"http: " <resources base=\"http: " <resource path=\"books\">\n" + " <method name=\"GET\"/>\n" + " <resource path=\"{bookId}\">\n" + " <param required=\"true\" style=\"template\" name=\"bookId\"/>\n" + " <method name=\"GET\"/>\n" + " <method name=\"DELETE\"/>\n" + " <resource path=\"reviews\">\n" + " <method name=\"GET\">\n" + " <request>\n" + " <param name=\"page\" required=\"false\" default=\"1\" style=\"query\"/>\n" + " <param name=\"size\" required=\"false\" default=\"20\" style=\"query\"/>\n" + " </request>\n" + " </method>\n" + " </resource>\n" + " </resource>\n" + " </resource>\n" + " <resource path=\"readers\">\n" + " <method name=\"GET\"/>\n" + " </resource>\n" + " </resources>\n" + "</application>").getBytes())); final String json = new WadlDocumentToJson().convert(doc); assertEquals("{\"application\":{\"xmlns\":\"http: + ",\"resource\":[{\"path\":\"books\",\"method\":[{\"name\":\"GET\"}],\"resource\":[{\"path\":\"{bookId}\",\"param\":[{\"name\"" + ":\"bookId\",\"required\":\"true\",\"style\":\"template\"}],\"method\":[{\"name\":\"GET\"},{\"name\":\"DELETE\"}],\"resource\"" + ":[{\"path\":\"reviews\",\"method\":[{\"name\":\"GET\",\"request\":[{\"param\":[{\"default\":\"1\",\"name\":\"page\",\"required\"" + ":\"false\",\"style\":\"query\"},{\"default\":\"20\",\"name\":\"size\",\"required\":\"false\",\"style\":\"query\"}]}]}]}]}]},{\"path\"" + ":\"readers\",\"method\":[{\"name\":\"GET\"}]}]}]}}", json); }