As a quick sanity test, the following works ok
yep, that does work ok
Sketch of Java code to achieve what you want
I guess "your_unmarshal" is the missing piece. Shouldn't I use JaxbXmlPart::unmarshal() ??
I can actually get it to work in Java, but not in Kotlin (weirdly)...
Here is some working Java code:
Using java Syntax Highlighting
var part
= new KeyMapCustomizationsPart
();
part.
unmarshal(new FileInputStream("src/test/resources/customization.xml"));
// var object = part.getContents(); <<< this fails at runtime with "CTTcg cannot be cast to class javax.xml.bind.JAXBElement"
Object object
= part.
getContents(); // <<< but this works ok
var tcg
= (CTTcg
) object
; // <<< intellij gives me this warning "Casting 'object' to 'CTTcg' will produce 'ClassCastException' for any non-null value", yet it compiles and runs??
tcg.
getAcds().
getAcd().
forEach((a
) -> System.
out.
println(a.
getAcdName())); // this prints the expected values
Parsed in 0.014 seconds, using
GeSHi 1.0.8.4
And if I don't use JaxbXmlPart's unmarshal, and hence don't call unwrap, then as your second sketch shows, I can set the contents correctly.
Kotlin:
Using java Syntax Highlighting
val part
= File("src/test/resources/customization.xml").
inputStream().
use {
KeyMapCustomizationsPart
().
apply { contents
= jaxbContext.
createUnmarshaller().
unmarshal(it
) as JAXBElement
<CTTcg
> }
}
Parsed in 0.014 seconds, using
GeSHi 1.0.8.4
I had a quick look at e.g. HeaderPart which uses the plain class as the generic type, rather than JAXBElement, and thought maybe KeyMapCustomizationsPart should be the same.
Anyway, I now have working code using the work-around shown above, so I'm grateful for your help.
Cheers.