JsonXmlSerializer { public String write(JSON json) { return write(json, null); } JsonXmlSerializer(); void addNamespace(String prefix, String uri); void addNamespace(String prefix, String uri, String elementName); void clearNamespaces(); void clearNamespaces(String elementName); String getArrayName(); String getElementName(); String[] getExpandableProperties(); String getObjectName(); String getRootName(); boolean isForceTopLevelObject(); boolean isNamespaceLenient(); boolean isRemoveNamespacePrefixFromElements(); boolean isSkipNamespaces(); boolean isSkipWhitespace(); boolean isTrimSpaces(); boolean isTypeHintsCompatibility(); boolean isTypeHintsEnabled(); JSON read(String xml); JSON readFromFile(File file); JSON readFromFile(String path); JSON readFromStream(InputStream stream); void removeNamespace(String prefix); void removeNamespace(String prefix, String elementName); void setArrayName(String arrayName); void setElementName(String elementName); void setExpandableProperties(String[] expandableProperties); void setForceTopLevelObject(boolean forceTopLevelObject); void setNamespace(String prefix, String uri); void setNamespace(String prefix, String uri, String elementName); void setNamespaceLenient(boolean namespaceLenient); void setObjectName(String objectName); void setRemoveNamespacePrefixFromElements(boolean removeNamespacePrefixFromElements); void setRootName(String rootName); void setSkipNamespaces(boolean skipNamespaces); void setSkipWhitespace(boolean skipWhitespace); void setTrimSpaces(boolean trimSpaces); void setTypeHintsCompatibility(boolean typeHintsCompatibility); void setTypeHintsEnabled(boolean typeHintsEnabled); String write(JSON json); String write(JSON json, String encoding);  }
@Test public void serializesJsonWithVanillaNames() throws Exception { JSON parse = new JsonUtil().parseTrimmedText("{ name: 'Barack', surname: 'Obama', profession: 'president'}"); assertThat(serializer.write(parse), is("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<o>" + "<name type=\"string\">Barack</name>" + "<profession type=\"string\">president</profession>" + "<surname type=\"string\">Obama</surname>" + "</o>\r\n")); }
@Test public void serializesJsonWithDollarSign() throws Exception { JSON parse = new JsonUtil().parseTrimmedText("{ $: 'value' }"); assertThat(serializer.write(parse), is("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<o>" + "<_ type=\"string\">value</_>" + "</o>\r\n")); }