Simpler helper method to convert DOM node back to JSON. The node MUST
have the "type" attributes (generated with addTypeAttributes flag set as
true).

@param node The DOM Node
@return The JSON string
@throws IOException
188436
public static String convertToJson(Node node) throws IOException {
        try (StringWriter writer = new StringWriter(); JsonGenerator generator = new JsonFactory().createGenerator(writer)) {
            convertToJson(node, generator, name -> name);
            return writer.toString();
        }
    }
742814
public static byte[] serialize(Node inputNode) throws Exception
	{
		// Initialize sources and targets
		ByteArrayOutputStream serializerOutput = new ByteArrayOutputStream();
		Source sourceObject = new DOMSource(inputNode); 
		Result targetObject = new StreamResult(serializerOutput);
		
		// Create XML Transformer
		TransformerFactory serializerFactory = TransformerFactory.newInstance();
		Transformer serializer = serializerFactory.newTransformer();

		// Set output properties
		serializer.setOutputProperty(OutputKeys.INDENT, "yes");
		serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
		
		// Run serialization transformation
		serializer.transform(sourceObject, targetObject);
		
		// Return output as a byte array
		return serializerOutput.toByteArray();
	}
1073243
public static Date convertDate(JsonNode node) {
        if (node instanceof POJONode) {
            return convertDate(DPathUtils.extractValue((POJONode) node));
        }
        DateFormat df = new SimpleDateFormat();
        try {
            return node.isNumber() ? new Date(node.asLong())
                    : node.isTextual() ? df.parse(node.asText()) : null;
        } catch (ParseException e) {
            return null;
        }
    }
801220
public static Collection<Attribute> fromJson(ObjectNode object) throws IOException {
        Collection<Attribute> attributes = new HashSet<>();
        convertJsonObject(attributes, object, "", 0, new HashMap<>());

        return attributes;
    }
38878
public static String stringify(final JsonNode json) {
        try {
            return json != null ? createObjectMapper().writeValueAsString(json) : "{}";
        } catch (JsonProcessingException jpx) {
            throw new RuntimeException("A problem occurred while stringifying a JsonNode: " + jpx.getMessage(), jpx);
        }
    }
175340
public static JsonNode stringToJsonNode(String paramName, String val) {
        if (val == null) {
            return null;
        }
        try {
            return MAPPER.readTree(val);
        } catch (IOException e) {
            throw new SdkClientException(paramName + " must be a valid JSON document", e);
        }
    }
650538
private String toText(AstNode node) throws IOException {
    StringBuilder out = new StringBuilder();
    if (node instanceof StringContentNode) {
      out.append(((StringContentNode)node).getContent());
    } else if (node instanceof ContentNode) {
      NodeList nodes = ((ContentNode) node).getContent();
      for (AstNode subNode : nodes) {
        out.append(toText(subNode));
      }
    }
    return out.toString();
  }
212430
public JSONObject toJSON() {
        try {
            return new JSONObject(properties).putOpt("name", getName());
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e(TAG, e, "toJSON()");
            throw new RuntimeAssertion("NodeEntry.toJSON() failed for '%s'", this);
        }
    }
929218
public static Node requiredNode(Model mo, JSONObject o, String id) throws JSONConverterException {
        checkKeys(o, id);
        try {
            return getNode(mo, (Integer) o.get(id));
        } catch (ClassCastException e) {
            throw new JSONConverterException("Unable to read a Node identifier from string at key '" + id + "'", e);
        }
    }
386355
public void serialize(Node node) throws IOException
    {

        try
        {
            TreeWalker walker =
                new TreeWalker(this);

            walker.traverse(node);
        }
        catch (org.xml.sax.SAXException se)
        {
            throw new WrappedRuntimeException(se);
        }
    }
482938
public ObjectNode toJson() {
		ObjectMapper mapper = new ObjectMapper();
		ObjectNode node = mapper.createObjectNode();
		ObjectNode attributeNode = mapper.createObjectNode();

		node.put(attribute.getCode(), attributeNode);
		attributeNode.put("op", operation.getOp());

		return node;
	}
932922
private String toXml(Node node) {
        try {
            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            StreamResult result = new StreamResult(new StringWriter());
            DOMSource source = new DOMSource(node);
            transformer.transform(source, result);
            return result.getWriter().toString();
          } catch(TransformerException ex) {
              throw new IllegalArgumentException("Could not transform "  +node + " to XML", ex);
          }
    }
884581
private void processNode(Node node) throws IOException {
		for (Node cursor = node.getFirstChild(); cursor != null; cursor = cursor.getNext()) {
			int lineno = cursor.getLineno()-1;	// adjust for rhino line numbers being 1 based
			int charno = cursor.getCharno();
			if (lineno > currentLine || lineno == currentLine && charno > currentChar) {
				currentLine = lineno;
				currentChar = charno;
			}
			FilePosition endPosition = getEndPosition(cursor);
			sgen.addMapping(name, null,
					new FilePosition(currentLine, currentChar),
					new FilePosition(currentLine, currentChar),
					endPosition);
			if (cursor.hasChildren()) {
				processNode(cursor);
			}
		}
	}
614956
public static String node2String(final Node node) throws UnsupportedEncodingException
   {
      return node2String(node, true, Constants.DEFAULT_XML_CHARSET);
   }
408833
public static JsonNode toJson(Object obj, ClassLoader classLoader) {
        return SerializationUtils.toJson(obj, classLoader);
    }
28006
public String createQueryStringFromNode(Node node, @Nullable Class<?> domainType) {
		return createQueryStringFromNode(node, 0, domainType);
	}
1084375
@Deprecated
    protected static byte[] nodeToByte(Node node) throws PolicyIndexException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Writer output = new OutputStreamWriter(out, Charset.forName("UTF-8"));

        try {
            SunXmlSerializers.writePrettyPrintWithDecl(node, output);
            output.close();
        } catch (IOException e) {
            throw new PolicyIndexException("Failed to serialise node " + e.getMessage(), e);
        }
        return out.toByteArray();
    }