ToolSpec { String toXMlFormatted() throws JAXBException, UnsupportedEncodingException { Marshaller m = jc.createMarshaller(); m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE ); m.setProperty( Marshaller.JAXB_ENCODING, "UTF-8" ); ByteArrayOutputStream bos = new ByteArrayOutputStream(); m.marshal(this, bos); return bos.toString("UTF-8"); }  void setId(String id); String getId(); Version getVersion(); void setVersion(Version version); Tool getTool(); void setTool(Tool tool); List<Var> getEnv(); void setEnv(List<Var> env); List<Template> getTemplate(); void setTemplate(List<Template> template); Inputs getInputs(); void setInputs(Inputs parameters); List<Action> getActions(); void setActions(List<Action> actions); static ToolSpec fromInputStream( InputStream input ); static final String NS; }
@Test public void testToXMlFormatted() throws FileNotFoundException, JAXBException, UnsupportedEncodingException { ToolSpec pts = ToolSpec.fromInputStream( ToolSpec.class.getResourceAsStream(KAKADU_SPEC)); System.out.println("In = "+pts.toXMlFormatted()); String xml = pts.toXMlFormatted(); ToolSpec pts2 = ToolSpec.fromInputStream( new ByteArrayInputStream( xml.getBytes("UTF-8") )); if( ! pts.equals( pts ) ) { System.out.println("Out = "+pts2.toXMlFormatted()); fail("Round-trip to XML and back lost some data."); } }