Hi,
I tried to convert a JSON response from CouchDB
(.../_all_docs?include_docs=true) to XML, unfortunately it's incomplete
(contains only <total_rows>2</total_rows>).
It's reproducible with DOM4JProviderTest:
@Test
public void testReadJSONArrayConvertToXML() throws Exception {
final String json = "{\"total_rows\":2,\"offset\":0,\"rows\":[\n" +
"{\"id\":\"test2 [ at ] test.de\",\"value\":{\"rev\":\"1-2a93d664b63033378e7896a2d89d9e3a\"},\"doc\":{\"_id\":\"test2 [ at ] test.de\",\"_rev\":\"1-2a93d664b63033378e7896a2d89d9e3a\",\"email\":\"test2 [ at ] test.de\"}},\n"
"{\"id\":\"test [ at ] test.de\",\"value\":{\"rev\":\"1-00340568a529de9f0af61a41ed111158\"},\"doc\":{\"_id\":\"test [ at ] test.de\",\"_rev\":\"1-00340568a529de9f0af61a41ed111158\",\"email\":\"test [ at ] test.de\"}}\n"
"]}";
String str = convertJsonToXml(json);
// starts with the xml PI
assertTrue(str.contains("test [ at ] test.de"));
private String convertJsonToXml(final String xml) throws IOException {
DOM4JProvider p = new DOM4JProvider();
p.setProviders(new ProvidersImpl(createMessage()));
org.dom4j.Document dom = p.readFrom(org.dom4j.Document.class,
org.dom4j.Document.class,
new Annotation[]{}, MediaType.APPLICATION_JSON_TYPE, new
MetadataMap<String, String>(),
new ByteArrayInputStream(xml.getBytes("UTF-8")));
return dom.asXML();
How can I fix this? Should I open a JIRA issue for it?
Cheers
Dennis
I tried to convert a JSON response from CouchDB
(.../_all_docs?include_docs=true) to XML, unfortunately it's incomplete
(contains only <total_rows>2</total_rows>).
It's reproducible with DOM4JProviderTest:
@Test
public void testReadJSONArrayConvertToXML() throws Exception {
final String json = "{\"total_rows\":2,\"offset\":0,\"rows\":[\n" +
"{\"id\":\"test2 [ at ] test.de\",\"value\":{\"rev\":\"1-2a93d664b63033378e7896a2d89d9e3a\"},\"doc\":{\"_id\":\"test2 [ at ] test.de\",\"_rev\":\"1-2a93d664b63033378e7896a2d89d9e3a\",\"email\":\"test2 [ at ] test.de\"}},\n"
"{\"id\":\"test [ at ] test.de\",\"value\":{\"rev\":\"1-00340568a529de9f0af61a41ed111158\"},\"doc\":{\"_id\":\"test [ at ] test.de\",\"_rev\":\"1-00340568a529de9f0af61a41ed111158\",\"email\":\"test [ at ] test.de\"}}\n"
"]}";
String str = convertJsonToXml(json);
// starts with the xml PI
assertTrue(str.contains("test [ at ] test.de"));
private String convertJsonToXml(final String xml) throws IOException {
DOM4JProvider p = new DOM4JProvider();
p.setProviders(new ProvidersImpl(createMessage()));
org.dom4j.Document dom = p.readFrom(org.dom4j.Document.class,
org.dom4j.Document.class,
new Annotation[]{}, MediaType.APPLICATION_JSON_TYPE, new
MetadataMap<String, String>(),
new ByteArrayInputStream(xml.getBytes("UTF-8")));
return dom.asXML();
How can I fix this? Should I open a JIRA issue for it?
Cheers
Dennis