Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB - why can i only marshal to a stream/file?

Tags:

java

xml

jaxb

i´m currently working on a project, with following architecture:

project A (shall storage files into a folder. Shall take byte[] and name and should write the data in a file. Not more, just a dumb file-writer application)

project B (shall read data from database, generates a xml file of it and sends that as byte[] to project A, which writes this in filesystem)

Now my problem: In project B, i want to generate the xml-file as an object, but the API of the Jaxb-Marshaller gives only marshal() methods, which takes as argument a Writer/File/OutputStream...And i don´t want to give a File or OutputStream in the project B- this should be task of Project A...

So why is there no method which returns the generated XML as Object or as byte[] or else?

like image 220
goblingift Avatar asked Nov 27 '25 01:11

goblingift


1 Answers

Pass in ByteArrayOutputStream. Then you can convert it to byte[] using toByteArray()

like image 184
user3707125 Avatar answered Nov 29 '25 14:11

user3707125