|
|
Re: xsi:type with namespace using MOXy [message #1044267 is a reply to message #1043581] |
Thu, 18 April 2013 17:36 |
M Fischer Messages: 2 Registered: April 2013 |
Junior Member |
|
|
Denise, thanks for the reply. We are using version 2.4.0. Here's some more information.
Here's an example of what we're seeing:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<MyContainer xmlns:xsi="hxxp://www.w3.org/2001/XMLSchema-instance">
<aaa xsi:type="bbB" name="foo" attrFromB="bar" />
<aaa xsi:type="ccC" name="foo" attrFromC="bar" />
</MyContainer>
Class BbB:
package com.example.model;
public class BbB extends AaA{
private String attrFromB;
public String getAttrFromB() {
return attrFromB;
}
public void setAttrFromB(String value) {
attrFromB = value;
}
}
Binding:
<?xml version="1.0"?>
<xml-bindings xmlns="hxxp://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="com.example.model">
<xml-schema>
<xml-ns prefix="xsi" namespace-uri="hxxp://www.w3.org/2001/XMLSchema-instance" />
</xml-schema>
<java-types>
<java-type name="BbB" xml-accessor-type="NONE">
<java-attributes>
<xml-attribute java-attribute="attrFromB" />
</java-attributes>
</java-type>
<java-type name="CcC" xml-accessor-type="NONE">
<java-attributes>
<xml-attribute java-attribute="attrFromC" />
</java-attributes>
</java-type>
<java-type name="MyContainerClass" xml-accessor-type="NONE">
<xml-root-element name="MyContainer" />
<java-attributes>
<xml-element java-attribute="bbb" xml-path="aaa[@xsi:type='bbB'])" />
<xml-element java-attribute="ccc" xml-path="aaa[@xsi:type='ccC'])" />
</java-attributes>
</java-type>
</java-types>
</xml-bindings>
Java:
public static void main(String[] args) throws Exception
{
Map<String, Object> properties = new HashMap<String, Object>(1);
properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, "testBinding.xml");
JAXBContext jc = JAXBContext.newInstance(new Class[] { MyContainerClass.class }, properties);
Unmarshaller unmarshaller = jc.createUnmarshaller();
InputStream isa = TestDemo.class.getClassLoader().getResourceAsStream("testDemo.xml");
MyContainerClass container = (MyContainerClass) unmarshaller.unmarshal(isa);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(container, System.out);
}
That all works fine.
However, our data comes in with a namespace on the xsi:type, so something like:
<?xml version="1.0" encoding="UTF-8"?>
<MyContainer xmlns:xsi="hxxp://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="hxxp://www.model.example.com">
<aaa xsi:type="ns1:BbBType" name="foo" attrFromB="bar" />
<aaa xsi:type="ns1:CcCType" name="foo" attrFromC="bar" />
</MyContainer>
When we update the binding for that xml-path, it throws this exception:
Exception in thread "main" javax.xml.bind.UnmarshalException
- with linked exception:
[Exception [EclipseLink-43] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Missing class for indicator field value [ns1:BbBType] of type [class java.lang.String].
Descriptor: XMLDescriptor(com.example.model.BbB --> [])]
at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:158)
at com.example.test.TestDemo.main(TestDemo.java:29)
Caused by: Exception [EclipseLink-43] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Missing class for indicator field value [ns1:BbBType] of type [class java.lang.String].
Descriptor: XMLDescriptor(com.example.model.BbB --> [])
at org.eclipse.persistence.exceptions.DescriptorException.missingClassForIndicatorFieldValue(DescriptorException.java:937)
at org.eclipse.persistence.internal.oxm.QNameInheritancePolicy.classFromRow(QNameInheritancePolicy.java:199)
at org.eclipse.persistence.internal.oxm.XMLRelationshipMappingNodeValue.processChild(XMLRelationshipMappingNodeValue.java:61)
at org.eclipse.persistence.internal.oxm.XMLCompositeObjectMappingNodeValue.startElement(XMLCompositeObjectMappingNodeValue.java:323)
at org.eclipse.persistence.oxm.record.UnmarshalRecord.startElement(UnmarshalRecord.java:783)
at org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader.parseEvent(XMLStreamReaderReader.java:114)
at org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader.parse(XMLStreamReaderReader.java:83)
at org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader.parse(XMLStreamReaderReader.java:72)
at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:794)
at org.eclipse.persistence.oxm.XMLUnmarshaller.unmarshal(XMLUnmarshaller.java:660)
at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:526)
at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:149)
... 1 more
Creating an object and marshaling it with the namespaced xsi:type writes out correctly (the xml sample above). Any guidance you can provide is appreciated.
[Updated on: Thu, 18 April 2013 17:38] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04254 seconds