SimpleMarshallerImpl implements SimpleMarshaller { @Override public ByteArrayOutputStream marshalAsByteArrayOutputStream(Object obj) throws SimpleMarshallerException { try { final ByteArrayOutputStream marshalresult = new ByteArrayOutputStream(); JAXBContext jaxbContext; jaxbContext = JAXBContext.newInstance(obj.getClass()); final Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(obj, marshalresult); return marshalresult; } catch (final Exception e) { throw new SimpleMarshallerException(e); } }  @Override String marshal(Object obj); @Override ByteArrayOutputStream marshalAsByteArrayOutputStream(Object obj); @SuppressWarnings("unchecked") @Override String marshalWithoutRootElement(T obj); @Override T unmarshalFromXml(Class<T> clazz, String xml);  }
@Test public void testMarshalAsByteArrayOutputStream() throws SimpleMarshallerException, SAXException, IOException { XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreWhitespace(true); final String expectedOutput = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ruleExecutionContainer><executionResponseList/></ruleExecutionContainer>"; final RuleExecutionContainer r = createRuleExecutionContainer(); final ByteArrayOutputStream output = marshaller .marshalAsByteArrayOutputStream(r); assertNotNull(output); assertXMLEqual(expectedOutput, output.toString()); }