Here is my problem....
I have a package of domain classes that have been annotated and produce my desired XML. I have a package-info.java that defines the default namespace for elements in this package as well as the XHTML namespace since some of the elements produce XHTML.
@javax.xml.bind.annotation.XmlSchema (
namespace = "default-namespace", elementFormDefault=javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
xmlns = {@javax.xml.bind.annotation.XmlNs(prefix="xhtml", namespaceURI="xhtml")}
)
This is all working and my unit and integration tests run fine. The XML looks like:
<person xmlns="default-namespace" xmlns:xhtml="xhtml"><address>...</address><summary><xhtml:div><xhtml:p>John Smith of 123 Cranberry Lane</xhtml:p></xhtml:div></summary></person>
In a second package, I have another set of classes that have been annotated and produce desired XML. There is also a package-info.java that defines the default namespace for this package:
@javax.xml.bind.annotation.XmlSchema (namespace = "default-namespace-2", elementFormDefault=javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
This too all works and the XML looks like:
<feed xmlns="default-namespace-2"><entry><title>Person #1</title></entry></feed>
The problem is that I've now added an element from the first package as a field of an object in the second package. It's defined as an Object because it can hold any of the elements from the first package. I also have a string that is mapped to an attribute of the XML so that I can indicate the type:
class Entry {
String title
@XmlPath("resource/@type")
String resourceType
Object resource
}
In my produced XML, I'd like to see is something like this:
<feed xmlns="default-namespace-2"><entry><title>Person #1</title>
<resource type="person">
<person xmlns="default-namespace" xmlns:xhtml="xhtml">
<address>...</address>
<summary><xhtml:div><xhtml:p>John Smith of 123 Cranberry Lane</xhtml:p></xhtml:div></summary>
</person>
</resource>
</entry></feed>
Instead, I get something that I don't think is the same
<feed xmlns="default-namespace-2"><entry><title>Person #1</title>
<resource type="person" xmlns:ns0="default-namespace" xmlns:xsi="XMLSchema-instance" xsi:type="ns0:person">
<ns0:address>...</ns0:address>
<ns0:summary></ns0:summary>
</person>
</entry></feed>
Obviously I have my mapping wrong. But I'm not sure what the proper mapping would be.
The other thought that I had was if I could somehow call a converter for the Object resource element, I could then inject the proper XML at that point.
Is there an easy way to get the XML that I want?