use of javax.xml.bind.Marshaller in project tomee by apache.
the class Info method marshaller.
private static Marshaller marshaller() throws JAXBException {
final Marshaller marshaller = JAXB_CONTEXT.createMarshaller();
marshaller.setProperty("jaxb.formatted.output", true);
return marshaller;
}
use of javax.xml.bind.Marshaller in project webservices-axiom by apache.
the class TestGetSAXResultJAXB method runTest.
@Override
protected void runTest() throws Throwable {
List<OrderItem> items = new ArrayList<OrderItem>(2);
OrderItem item = new OrderItem();
item.setPartId("P85-137-19");
item.setQuantity(2);
items.add(item);
item = new OrderItem();
item.setPartId("O85-554-66");
item.setQuantity(1);
items.add(item);
Order order = new Order();
order.setCustomerId("73107481");
order.setItems(items);
Marshaller marshaller = JAXBContext.newInstance(Order.class).createMarshaller();
StringWriter out = new StringWriter();
marshaller.marshal(order, out);
OMDocument document = metaFactory.getOMFactory().createOMDocument();
marshaller.marshal(order, document.getSAXResult().getHandler());
assertAbout(xml()).that(xml(OMDocument.class, document)).hasSameContentAs(out.toString());
}
use of javax.xml.bind.Marshaller in project tomee by apache.
the class JaxbJavaee method marshal.
public static <T> void marshal(final Class<T> type, final Object object, final OutputStream out) throws JAXBException {
final JAXBContext ctx2 = JaxbJavaee.getContext(type);
final Marshaller marshaller = ctx2.createMarshaller();
marshaller.setProperty("jaxb.formatted.output", true);
marshaller.marshal(object, out);
}
use of javax.xml.bind.Marshaller in project tomee by apache.
the class JpaJaxbUtil method marshal.
public static <T> String marshal(final Class<T> type, final Object object) throws JAXBException {
final JAXBContext ctx2 = JAXBContextFactory.newInstance(type);
final Marshaller marshaller = ctx2.createMarshaller();
marshaller.setProperty("jaxb.formatted.output", true);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
marshaller.marshal(object, baos);
return new String(baos.toByteArray());
}
use of javax.xml.bind.Marshaller in project tomee by apache.
the class OpenejbJarTest method testAll.
public void testAll() throws Exception {
final JAXBContext ctx = JAXBContextFactory.newInstance(OpenejbJar.class);
final Unmarshaller unmarshaller = ctx.createUnmarshaller();
final InputStream in = this.getClass().getClassLoader().getResourceAsStream("openejb-jar.xml");
final String expected = readContent(in);
unmarshaller.setEventHandler(new TestValidationEventHandler());
final Object object = unmarshaller.unmarshal(new ByteArrayInputStream(expected.getBytes()));
assertTrue(object instanceof OpenejbJar);
final Marshaller marshaller = ctx.createMarshaller();
marshaller.setProperty("jaxb.formatted.output", true);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
marshaller.marshal(object, baos);
final String actual = new String(baos.toByteArray());
XMLUnit.setIgnoreWhitespace(true);
try {
final Diff myDiff = new DetailedDiff(new Diff(expected, actual));
assertTrue("Files are not similar " + myDiff, myDiff.similar());
} catch (final AssertionFailedError e) {
e.printStackTrace();
assertEquals(expected, actual);
throw e;
}
}
Aggregations