Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAXB mashalling?

 
M Burke
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JAXB generated object in memory, and I want to mashal it to XML. But I want it directly as a String, not written out to a file. How do I do this? Right now, I am using a temperary file, like this...

JAXBContext jc = JAXBContext.newInstance(JAXB_PACKAGE);
Marshaller m = jc.createMarshaller();
OutputStream os = new FileOutputStream("temp.xml");
m.marshal(jaxbObj, os);
os.close();

byte[] bXml = ioMgr.loadFileAsBuffer("temp.xml");
if(bXml != null){
xml = new String(bXml);
}
ioMgr.removeFile("temp.xml");
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
M Burke
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That worked great, thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic