Note that there are some explanatory texts on larger screens.

plurals
  1. POMOXy marshalling wrong object
    text
    copied!<p>I'm trying to have docx4j support MOXy as its JAXB implementation. </p> <p>We're pretty much there; see <a href="http://www.docx4java.org/forums/docx-java-f6/moxy-t1242.html" rel="nofollow">docx4j and MOXy</a></p> <p>The problem I'm having is that I have a <a href="https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/wml/Text.java" rel="nofollow">class</a>:</p> <pre><code>@XmlAccessorType(XmlAccessType.FIELD) @XmlType(namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", name = "CT_Text", propOrder = { "value" }) @XmlRootElement(name = "t") public class Text </code></pre> <p>MOXy is marshalling this to w:delInstrText, instead of w:t, which is what I'd expect/hope, and what the Java 6 / reference implementations do.</p> <p>From the <a href="https://github.com/plutext/docx4j/blob/master/xsd/wml/wml.xsd" rel="nofollow">schema</a>:</p> <pre><code> &lt;xsd:element name="t" type="CT_Text"&gt; &lt;xsd:annotation&gt; &lt;xsd:documentation&gt;Text&lt;/xsd:documentation&gt; &lt;/xsd:annotation&gt; &lt;/xsd:element&gt; &lt;xsd:element name="delInstrText" type="CT_Text"&gt; &lt;xsd:annotation&gt; &lt;xsd:documentation&gt;Deleted Field Code&lt;/xsd:documentation&gt; &lt;/xsd:annotation&gt; &lt;/xsd:element&gt; </code></pre> <p>FWIW, ObjectFactory contains:</p> <pre><code>public Text createText() { return new Text(); } @XmlElementDecl(namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", name = "delInstrText", scope = R.class) public JAXBElement&lt;Text&gt; createRDelInstrText(Text value) { return new JAXBElement&lt;Text&gt;(_RDelInstrText_QNAME, Text.class, R.class, value); } </code></pre> <p>This is with MOXy jars:</p> <pre><code> +- org.eclipse.persistence:org.eclipse.persistence.moxy:jar:2.4.1 | +- org.eclipse.persistence:org.eclipse.persistence.core:jar:2.4.1 | | \- org.eclipse.persistence:org.eclipse.persistence.asm:jar:3.3.1.v201206041142 | \- org.eclipse.persistence:org.eclipse.persistence.antlr:jar:3.2.0.v201206041011 </code></pre> <p><strong>Update:</strong></p> <p>Here is a test case:</p> <pre><code>import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.Marshaller; import org.docx4j.wml.R; import org.docx4j.wml.Text; public class MOXyTest { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance("org.docx4j.wml"); // System.out.println(Version.getVersion()); // System.out.println(jc.getClass()); R run = new R(); Text text = new Text(); run.getContent().add(text); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(run, System.out); } } </code></pre>
 

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