mirror of https://github.com/apache/jclouds.git
Make JAXB XML marshaller pretty-print
This commit is contained in:
parent
4fdaa3b6a6
commit
7ca842f44c
|
@ -28,7 +28,6 @@ import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.bind.Marshaller;
|
import javax.xml.bind.Marshaller;
|
||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
|
||||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
|
||||||
import org.jclouds.xml.XMLParser;
|
import org.jclouds.xml.XMLParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,6 +48,7 @@ public class JAXBParser implements XMLParser {
|
||||||
try {
|
try {
|
||||||
JAXBContext context = JAXBContext.newInstance(type);
|
JAXBContext context = JAXBContext.newInstance(type);
|
||||||
Marshaller marshaller = context.createMarshaller();
|
Marshaller marshaller = context.createMarshaller();
|
||||||
|
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
marshaller.marshal(src, writer);
|
marshaller.marshal(src, writer);
|
||||||
return writer.toString();
|
return writer.toString();
|
||||||
|
@ -57,7 +57,6 @@ public class JAXBParser implements XMLParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T fromXML(final String xml, final Class<T> type) throws IOException {
|
public <T> T fromXML(final String xml, final Class<T> type) throws IOException {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rest.binders;
|
package org.jclouds.rest.binders;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.*;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
|
@ -52,8 +52,7 @@ public class BindToXMLPayloadTest {
|
||||||
|
|
||||||
HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://momma")).build();
|
HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://momma")).build();
|
||||||
request = binder.bindToRequest(request, obj);
|
request = binder.bindToRequest(request, obj);
|
||||||
assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER
|
assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER + "\n<test>\n <elem>Hello World</elem>\n</test>\n");
|
||||||
+ "<test><elem>Hello World</elem></test>");
|
|
||||||
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.APPLICATION_XML);
|
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.APPLICATION_XML);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,8 +71,7 @@ public class BindToXMLPayloadTest {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
request = binder.bindToRequest(request, obj);
|
request = binder.bindToRequest(request, obj);
|
||||||
assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER
|
assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER + "\n<test>\n <elem>Hello World</elem>\n</test>\n");
|
||||||
+ "<test><elem>Hello World</elem></test>");
|
|
||||||
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.APPLICATION_XML);
|
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.APPLICATION_XML);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue