List of usage examples for javax.xml.bind Marshaller JAXB_FORMATTED_OUTPUT
String JAXB_FORMATTED_OUTPUT
To view the source code for javax.xml.bind Marshaller JAXB_FORMATTED_OUTPUT.
Click Source Link
From source file:net.orpiske.sas.commons.xml.XmlWriterUtils.java
/** * Marshals an object into a formatted XML document * @param element the JAXB element object that represents an 'object' of * type T/*from www. jav a 2s .co m*/ * @param object the object to be transformed into XML * @param stream the output stream * @throws JAXBException if unable to transform the object to XML */ public static <T> void marshal(JAXBElement<T> element, T object, OutputStream stream) throws JAXBException { JAXBContext context = JAXBContext.newInstance(object.getClass().getPackage().getName()); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(element, stream); }
From source file:org.bremersee.sms.test.ModelTests.java
@Test public void testXmlSmsSendRequestDto() throws Exception { System.out.println("Testing XML SmsSendRequestDto ..."); SmsSendRequestDto request = new SmsSendRequestDto("bremersee", "0123456789", "Hello", new Date(System.currentTimeMillis() + 30000L)); ByteArrayOutputStream out = new ByteArrayOutputStream(); Marshaller m = jaxbContext.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(request, out);// w w w . j a v a 2 s.c o m String xmlStr = new String(out.toByteArray(), "UTF-8"); System.out.println(xmlStr); SmsSendRequestDto readRequest = (SmsSendRequestDto) jaxbContext.createUnmarshaller() .unmarshal(new ByteArrayInputStream(xmlStr.getBytes("UTF-8"))); m.marshal(readRequest, System.out); TestCase.assertEquals(request, readRequest); System.out.println("OK\n"); }
From source file:io.konik.utils.InvoiceLoaderUtils.java
public static Marshaller createZfMarshaller() throws JAXBException { Marshaller marshaller = newInstance("io.konik.zugferd").createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, TRUE); return marshaller; }
From source file:com.cloudera.api.model.ApiModelTest.java
static String objectToXml(Object object) throws JAXBException, UnsupportedEncodingException { JAXBContext jc = JAXBContext.newInstance(object.getClass()); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); ByteArrayOutputStream baos = new ByteArrayOutputStream(); m.marshal(object, baos);/* w w w .j a v a2 s.c o m*/ return baos.toString(TEXT_ENCODING); }
From source file:grnet.com.entry.Actions.java
private void initMarshaller() throws JAXBException { context = JAXBContext.newInstance(Repository.class); marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); }
From source file:dk.statsbiblioteket.doms.licensemodule.integrationtest.LicenseModuleRestWSTester.java
@SuppressWarnings("all") private static void testValidateAccess() throws Exception { // Test Validate Access ValidateAccessInputDTO input = new ValidateAccessInputDTO(); ArrayList<UserObjAttributeDTO> userObjAttributes = createUserObjAttributeDTO(); input.setAttributes(userObjAttributes); ArrayList<String> groups = new ArrayList<String>(); groups.add("IndividueltForbud"); groups.add("Klausuleret"); input.setGroups(groups);//from w ww .j a v a 2s . com input.setPresentationType("images"); JAXBContext context = JAXBContext.newInstance(ValidateAccessInputDTO.class); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(input, outputStream); // serialize to XML String inputXML = outputStream.toString(); System.out.println("input xml:\n" + inputXML); ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource service = client .resource(UriBuilder.fromUri("http://localhost:8080/licensemodule/services/").build()); // Call with XML ValidateAccessOutputDTO output = service.path("validateAccess").type(MediaType.TEXT_XML) .accept(MediaType.TEXT_XML).entity(inputXML).post(ValidateAccessOutputDTO.class); // Call with @XmlRootElement // output = service.path("validateAccess").type(MediaType.TEXT_XML).accept(MediaType.TEXT_XML).entity(input).post(ValidateAccessOutputDTO.class); context = JAXBContext.newInstance(ValidateAccessOutputDTO.class); outputStream = new ByteArrayOutputStream(); m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(output, outputStream); // serialize to XML String outputXML = outputStream.toString(); System.out.println(outputXML); // Access depends on the licenses in the DB. System.out.println("access :" + output.isAccess()); }
From source file:org.bremersee.comparator.test.ComparatorItemTests.java
@Test public void testXmlComparatorItem() throws Exception { System.out.println("Testing XML write-read operations ..."); ComparatorItem item = new ComparatorItem("i0", true); item.next("i1", false).next("i2", true); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter sw = new StringWriter(); marshaller.marshal(item, sw);/*from w ww . ja v a2s . co m*/ String xmlStr = sw.toString(); System.out.println(xmlStr); ComparatorItem readItem = (ComparatorItem) jaxbContext.createUnmarshaller() .unmarshal(new StringReader(xmlStr)); System.out.println(item.toList(true)); System.out.println(readItem.toList(true)); TestCase.assertEquals(item.toList(true), readItem.toList(true)); System.out.println("OK\n"); }
From source file:eu.planets_project.tb.impl.serialization.ExperimentRecords.java
/** * @param exp/*w w w . j av a 2 s . co m*/ * @param out */ private static void writeToOutputStream(ExperimentRecords exp, OutputStream out) { try { JAXBContext jc = JAXBContext.newInstance(ExperimentRecords.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(exp, out); } catch (JAXBException e) { log.fatal("Writing Experiments to XML failed: " + e); } }
From source file:org.vertx.java.http.eventbusbridge.util.SerializationHelper.java
private static String toXml(final Object xmlObject) throws JAXBException { StringWriter writer = new StringWriter(); Marshaller jaxbMarshaller = JAXB_CONTEXT.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(xmlObject, writer); return writer.toString(); }
From source file:com.provenance.cloudprovenance.sconverter.PolicyResponseConverter.java
public String marhsallObject(PolicyResponse pResponse) { JAXBContext jaxbContext;/*www . j a v a 2s .c o m*/ StringWriter sw = new StringWriter(); try { jaxbContext = JAXBContext.newInstance(instanceDir); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", cProvPrefixMapper); JAXBElement<PolicyResponse> el = pFactory.createPolicyResponse(pResponse); marshaller.marshal(el, sw); logger.info("Sucessfully marshalled the policy objects: " + el.getName()); } catch (JAXBException e) { e.printStackTrace(); } return sw.toString(); }