JaxbObject { public T unMarshal(T expectedType, Reader reader) throws JAXBException { T object = null; try { Unmarshaller m = context.createUnmarshaller(); JAXBElement o = m.unmarshal(new StreamSource(reader), expectedType.getClass()); object = (T) o.getValue(); } catch (JAXBException jbe) { jbe.printStackTrace(); throw jbe; } return object; } JaxbObject(); Document marshalToDocument(T t); String marshal(T t); T unMarshal(T expectedType, Reader reader); T unMarshal(Document d, T expectedType);  }
@Test public void testUnMarshal() throws Exception { Log.info("unMarshal"); FileType type = new FileType(); type.setDisplayName("Display Name"); type.setExtension("extension"); type.setFileTypeId(-1); type.setMetaType("meta-type"); JaxbObject<FileType> instance = new JaxbObject<>(); String result = instance.marshal(type); Reader in = new StringReader(result); FileType type2 = instance.unMarshal(type, in); assertEquals(type, type2); }