@Test public void testMarshal() throws Exception { Log.info("marshal"); FileType type = new FileType(); type.setDisplayName("Display Name"); type.setExtension("extension"); type.setFileTypeId(-1); type.setMetaType("meta-type"); JaxbObject<FileType> instance = new JaxbObject<>(); String expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><FileType><displayName>Display Name</displayName><extension>extension</extension><fileTypeId>-1</fileTypeId><metaType>meta-type</metaType></FileType>"; String result = instance.marshal(type); assertEquals(expResult, result); }
public String marshal(T t) throws JAXBException { String output = null; try { StreamResult result = new StreamResult(new StringWriter()); T object = t; Marshaller m = context.createMarshaller(); m.marshal(new JAXBElement(new QName(object.getClass().getSimpleName()), object.getClass(), object), result); StringWriter writer = (StringWriter) result.getWriter(); StringBuffer buffer = writer.getBuffer(); output = buffer.toString(); } catch (JAXBException jbe) { jbe.printStackTrace(); throw jbe; } return output; }
JaxbObject { public String marshal(T t) throws JAXBException { String output = null; try { StreamResult result = new StreamResult(new StringWriter()); T object = t; Marshaller m = context.createMarshaller(); m.marshal(new JAXBElement(new QName(object.getClass().getSimpleName()), object.getClass(), object), result); StringWriter writer = (StringWriter) result.getWriter(); StringBuffer buffer = writer.getBuffer(); output = buffer.toString(); } catch (JAXBException jbe) { jbe.printStackTrace(); throw jbe; } return output; } }
JaxbObject { public String marshal(T t) throws JAXBException { String output = null; try { StreamResult result = new StreamResult(new StringWriter()); T object = t; Marshaller m = context.createMarshaller(); m.marshal(new JAXBElement(new QName(object.getClass().getSimpleName()), object.getClass(), object), result); StringWriter writer = (StringWriter) result.getWriter(); StringBuffer buffer = writer.getBuffer(); output = buffer.toString(); } catch (JAXBException jbe) { jbe.printStackTrace(); throw jbe; } return output; } JaxbObject(); }
JaxbObject { public String marshal(T t) throws JAXBException { String output = null; try { StreamResult result = new StreamResult(new StringWriter()); T object = t; Marshaller m = context.createMarshaller(); m.marshal(new JAXBElement(new QName(object.getClass().getSimpleName()), object.getClass(), object), result); StringWriter writer = (StringWriter) result.getWriter(); StringBuffer buffer = writer.getBuffer(); output = buffer.toString(); } catch (JAXBException jbe) { jbe.printStackTrace(); throw jbe; } return output; } JaxbObject(); Document marshalToDocument(T t); String marshal(T t); T unMarshal(T expectedType, Reader reader); T unMarshal(Document d, T expectedType); }
JaxbObject { public String marshal(T t) throws JAXBException { String output = null; try { StreamResult result = new StreamResult(new StringWriter()); T object = t; Marshaller m = context.createMarshaller(); m.marshal(new JAXBElement(new QName(object.getClass().getSimpleName()), object.getClass(), object), result); StringWriter writer = (StringWriter) result.getWriter(); StringBuffer buffer = writer.getBuffer(); output = buffer.toString(); } catch (JAXBException jbe) { jbe.printStackTrace(); throw jbe; } return output; } JaxbObject(); Document marshalToDocument(T t); String marshal(T t); T unMarshal(T expectedType, Reader reader); T unMarshal(Document d, T expectedType);  }