code: public static void convertToJson(Node node, JsonGenerator generator, ElementNameConverter converter) throws IOException {
          Element element;
          if (node instanceof Document) {
              element = ((Document) node).getDocumentElement();
          } else if (node instanceof Element) {
              element = (Element) node;
          } else {
              throw new IllegalArgumentException("Node must be either a Document or an Element");
          }
  
          TYPE type = toTYPE(element.getAttribute("type"));
          switch (type) {
              case OBJECT:
              case ARRAY:
                  convertElement(generator, element, true, converter);
                  break;
              default:
                  throw new RuntimeException("invalid root type [" + type + "]");
          }
          generator.close();
      }
docs: More complete helper method to convert DOM node back to JSON.The node
  MUST have the "type" attributes (generated with addTypeAttributes flag
  set as true).This method allows to customize the JsonGenerator.
  
  @param node The DOM Node
  @param generator A configured JsonGenerator
  @param converter Converter to convert elements names from XML to JSON
  @throws IOException