I use the following code to serialize a class:
public String serialize(T oObject)
{
mMarshaller = getJAXBContext().createMarshaller();
mMarshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8");
ByteArrayOutputStream strm = getOutputStream();
mMarshaller.marshal(oObject, strm);
return strm.toString();
}
But when I look at the generaetd XML there is a namespace in there:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mapEntry>
<key xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">
Key
</key>
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">
oValue
</value>
</mapEntry>
Is there some way to remove this, or tell JAXB that it should NOT add this? I'm looking at this now the whole morning and tried several things I found via google, but nothing helped.
Now I found this thread here: How to marshal without a namespace? but the problem is that the accepted answer is only partially listed and now I don't know if this would help me. XMLStreamWriter
is an interface, and I don't want to implement a whole stream writer just for that. So is there some way to extend the ByteArrayOutputStream
without the need of implementing all the other functions, such an XMLWriter would need?