Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for issue 212; deepCopy of a JAXBElement is broken (whether using…
… MOXy or Sun/Oracle)
- Loading branch information
Showing
2 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.docx4j; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import javax.xml.bind.JAXBElement; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.docx4j.jaxb.Context; | ||
import org.docx4j.wml.CTBookmark; | ||
import org.docx4j.wml.P; | ||
import org.docx4j.wml.R; | ||
import org.junit.Test; | ||
|
||
public class XmlUtilsDeepCopyTest { | ||
|
||
/** | ||
* Test for https://github.com/plutext/docx4j/issues/212 | ||
* | ||
* With v3.3.0 and 3.3.1, deepCopy of a JAXBElement was broken. | ||
* | ||
* With moxY: | ||
* | ||
* java.lang.IllegalArgumentException: javax.xml.bind.UnmarshalException | ||
* | ||
- with linked exception: | ||
[Exception [EclipseLink-25007] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.XMLMarshalException | ||
Exception Description: A descriptor for class javax.xml.bind.JAXBElement was not found in the project. | ||
For JAXB, if the JAXBContext was bootstrapped using TypeMappingInfo[] you must call a marshal method that accepts TypeMappingInfo | ||
as an input parameter.] | ||
* With Sun/Oracle, you got a JAXBElement, but null value | ||
*/ | ||
@Test | ||
public void testIssue212() { | ||
|
||
CTBookmark bookmark = Context.getWmlObjectFactory().createCTBookmark(); | ||
JAXBElement<CTBookmark> el =Context.getWmlObjectFactory().createBodyBookmarkStart(bookmark); | ||
|
||
Object o = XmlUtils.deepCopy(el); | ||
|
||
//System.out.println(XmlUtils.marshaltoString(o)); | ||
|
||
Assert.assertSame(el.getClass(), o.getClass()); | ||
Assert.assertSame(el.getValue().getClass(), ((JAXBElement)o).getValue().getClass()); | ||
} | ||
|
||
@Test | ||
public void testSimpleP() { | ||
|
||
P p = new P(); | ||
p.getContent().add( new R()); | ||
|
||
Object o = XmlUtils.deepCopy(p); | ||
|
||
Assert.assertSame(p.getClass(), o.getClass()); | ||
Assert.assertSame(p.getContent().get(0).getClass(), ((P)o).getContent().get(0).getClass()); | ||
|
||
|
||
} | ||
|
||
} |