Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When marshalling to an <code>OutputStream</code> using a combination of the following produces the expected output.</p> <pre><code> marshaller.setProperty("com.sun.xml.bind.xmlHeaders", "&lt;?xml version=\"1.0\"?&gt;"); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); </code></pre> <p>The problem you are seeing occurs when you marshal to a <code>Writer</code>, which appears to be a bug in the JAXB reference implementation. You can raise an issue at the link below:</p> <ul> <li><a href="https://java.net/jira/browse/JAXB/" rel="nofollow noreferrer">https://java.net/jira/browse/JAXB/</a></li> </ul> <hr> <p>You could always do:</p> <pre><code>JAXBContext context; try { context = JAXBContext.newInstance(heartbeat.getClass()); StringWriter writer = new StringWriter(); writer.append("&lt;?xml version=\"1.0\"?&gt;"); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); heartbeat.setHeader(header); heartbeat.setHeartbeatEvent(event); marshaller.marshal(heartbeat, writer); String stringXML = writer.toString(); return stringXML; } catch (JAXBException e) { throw new RuntimeException("Problems generating XML in specified " + "encoding, underlying problem is " + e.getMessage(), e); } </code></pre> <hr> <p><a href="http://www.eclipse.org/eclipselink/#moxy" rel="nofollow noreferrer"><strong>EclipseLink JAXB (MOXy)</strong></a> also supports the <code>com.sun.xml.bind.xmlHeaders</code> and it works correctly when marshalling to a <code>Writer</code> (I'm the MOXy lead)</p> <ul> <li><a href="http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html" rel="nofollow noreferrer">http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload