我試圖讓docx4j支持MOXy作爲它的JAXB實現。MOXy編組錯誤的對象
我們差不多;看到docx4j and MOXy
我遇到的問題是,我有一個class:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", name = "CT_Text", propOrder = {
"value"
})
@XmlRootElement(name = "t")
public class Text
莫西被編組此爲w:delInstrText,而不是寬:T,這是我的期望/希望,以及Java 6/reference實現的功能。
從schema:
<xsd:element name="t" type="CT_Text">
<xsd:annotation>
<xsd:documentation>Text</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="delInstrText" type="CT_Text">
<xsd:annotation>
<xsd:documentation>Deleted Field Code</xsd:documentation>
</xsd:annotation>
</xsd:element>
FWIW,ObjectFactory的包含:
public Text createText() {
return new Text();
}
@XmlElementDecl(namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", name = "delInstrText", scope = R.class)
public JAXBElement<Text> createRDelInstrText(Text value) {
return new JAXBElement<Text>(_RDelInstrText_QNAME, Text.class, R.class, value);
}
這是莫西罐子:
+- 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
更新:
下面是測試情況:
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);
}
}
我與再現問題上的演示代碼的變化更新的問題。謝謝! – JasonPlutext
@JasonPlutext - 感謝您更新您的問題。我已經用我們的發現更新了我的答案。 –
驗證,與eclipselink-2.4.2.v20121107這個問題似乎已經消失。感謝您查看這個。 – JasonPlutext