SOAPEnvelope orgEnvelope = factory.getDefaultEnvelope();
OMSourcedElement element = factory.createOMElement(new JAXBOMDataSource(context, object));
orgEnvelope.getBody().addChild(element);
// Serialize the message
OMOutputFormat format = new OMOutputFormat();
format.setDoOptimize(true);
ByteArrayOutputStream out = new ByteArrayOutputStream();
orgEnvelope.serialize(out, format);
assertFalse(element.isExpanded());
// Parse the serialized message
Attachments att = new Attachments(new ByteArrayInputStream(out.toByteArray()), format.getContentType());
assertEquals(2, att.getAllContentIDs().length);
SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(att).getSOAPEnvelope();
OMElement contentElement = envelope.getBody().getFirstElement().getFirstChildWithName(
new QName("http://ws.apache.org/axiom/test/jaxb", "content"));
OMText content = (OMText)contentElement.getFirstOMChild();