MarshallingService { public <T extends Object> T deserialize(InputStream inputStream, Class<T> type) throws Exception { Unmarshaller unmarshaller = createUnmarshaller(); unmarshaller.start(Marshalling.createByteInput(inputStream)); try { return type.cast(unmarshaller.readObject()); } finally { unmarshaller.finish(); } } MarshallingService(); void serialize(Object object, OutputStream outputStream); T deserialize(InputStream inputStream, Class<T> type);  }
@SuppressWarnings("unchecked") @Test public void testDeserialize() throws Exception { session.clear(); Collection<Customer> allData = getAllData(); marshallingService.serialize(allData, fileOutputStream); FileInputStream fileInputStream = new FileInputStream("marshalling.tmp"); Collection<Customer> loadAllData = marshallingService.deserialize(fileInputStream,Collection.class); Assert.assertTrue(CollectionUtils.isEqualCollection(allData, loadAllData, new CustomerEquator())); }