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