Note that there are some explanatory texts on larger screens.

plurals
  1. POMarshalling fails with exception about MarshallerImpl not known to this context
    primarykey
    data
    text
    <p>I have a relatively simple package of 8 Java classes generated from an XML schema using JAXB XJC. I also have a utility class to marshal and unmarshal instances of the class. </p> <h2>This works</h2> <p>The utility class can successfully unmarshal a valid XML document into an instance of the ‘root’ class <code>WordMergeInfo</code>. For example this works fine:</p> <pre><code> JAXBContext jc = JAXBContext.newInstance(WordMergeInfo.class); Unmarshaller um = jc.createUnmarshaller(); return (WordMergeInfo)um.unmarshal(inputStream); </code></pre> <h2>This doesn’t work</h2> <p>But marshalling to a string fails. In this code:</p> <pre><code> JAXBContext jc = JAXBContext.newInstance(WordMergeInfo.class); Marshaller m = jc.createMarshaller(); StringWriter writer = new StringWriter(); m.marshal(m, writer); return writer.toString(); </code></pre> <p>the call to <code>Marshaller.marshal</code> fails with the following error:</p> <pre><code>javax.xml.bind.JAXBException: class com.sun.xml.bind.v2.runtime.MarshallerImpl nor any of its super class is known to this context. at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:594) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:482) at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:315) at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:244) </code></pre> <p>As I understand it, <code>nor any of its super class is known to this context</code> means that a JAXB class needed for marshalling cannot be found. So why can’t one of the JAXB implementation classes be found, when the same class is in the stack trace?</p> <h2>Context</h2> <p>This error showed up in a unit test of my class, run under Maven. The dependencies are:</p> <ul> <li>javax.xml.bind:jaxb-api:2.1</li> <li>com.sun.xml.bind:jaxb-impl:2.1.13</li> </ul> <p>I got the same error with earlier versions of these (2.0 and 2.0.3, respectively).</p> <p>The Maven test class path is:</p> <pre><code>C:\Users\mstra.CUSTMAN\Workspace\DARTCorrModule\xml\target\test-classes C:\Users\mstra.CUSTMAN\Workspace\DARTCorrModule\xml\target\classes C:\Users\mstra.CUSTMAN\.m2\repository\javax\xml\bind\jaxb-api\2.1\jaxb-api-2.1.jar C:\Users\mstra.CUSTMAN\.m2\repository\javax\xml\stream\stax-api\1.0-2\stax-api-1.0-2.jar C:\Users\mstra.CUSTMAN\.m2\repository\javax\activation\activation\1.1\activation-1.1.jar C:\Users\mstra.CUSTMAN\.m2\repository\com\sun\xml\bind\jaxb-impl\2.1.13\jaxb-impl-2.1.13.jar C:\Users\mstra.CUSTMAN\.m2\repository\junit\junit\4.8.2\junit-4.8.2.jar C:\Users\mstra.CUSTMAN\.m2\repository\org\mockito\mockito-all\1.8.5\mockito-all-1.8.5.jar C:\Users\mstra.CUSTMAN\.m2\repository\javax\ejb\ejb-api\3.0\ejb-api-3.0.jar C:\Users\mstra.CUSTMAN\.m2\repository\org\slf4j\slf4j-api\1.6.4\slf4j-api-1.6.4.jar </code></pre> <p>Any insight is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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