MarshallingService { public void serialize(Object object, OutputStream outputStream) throws IOException { Marshaller marshaller = createMarshaller(); marshaller.start(Marshalling.createByteOutput(outputStream)); try { marshaller.writeObject(object); } finally { marshaller.finish(); } } MarshallingService(); void serialize(Object object, OutputStream outputStream); T deserialize(InputStream inputStream, Class<T> type);  }
@Test public void testSerialize() throws IOException { Collection<Customer> allData = getAllData(); marshallingService.serialize(allData, fileOutputStream); }