| Summary: | NPE thrown when @XmlValue mapping attempts to write xsi:type | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | z_Archived | Reporter: | Blaise Doughan <blaise.doughan> | ||||||
| Component: | Eclipselink | Assignee: | Nobody - feel free to take it <nobody> | ||||||
| Status: | RESOLVED FIXED | QA Contact: | |||||||
| Severity: | normal | ||||||||
| Priority: | P3 | ||||||||
| Version: | unspecified | ||||||||
| Target Milestone: | --- | ||||||||
| Hardware: | PC | ||||||||
| OS: | Windows XP | ||||||||
| URL: | http://stackoverflow.com/questions/7851506/jaxb-how-to-set-the-xsitype-of-a-xml-element-based-on-its-value | ||||||||
| Whiteboard: | |||||||||
| Attachments: |
|
||||||||
Created attachment 212752 [details]
MOXy - Test Cases
Created attachment 212753 [details]
Core - Fix
Fix checked into 2.3.3 at rev: 11004 Fix checked into trunk at rev: 11005 Code reviewed by: Matt MacIvor Fix Details: When writing out text in XMLCompositeObjectMappingNode value treat the XPath "@text" like ".". The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |
If you attempt to marshal an object like the following a NPE will be thrown when an xsi:type attribute needs to be written for the @XmlValue property. import javax.xml.bind.annotation.*; @XmlAccessorType(XmlAccessType.FIELD) public class Field { @XmlAttribute private String name; @XmlValue Object value; } Exception Exception in thread "main" javax.xml.bind.MarshalException - with linked exception: [Exception [EclipseLink-25003] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.XMLMarshalException Exception Description: An error occurred marshalling the object Internal Exception: java.lang.NullPointerException] at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:314) at forum7851506.Demo.main(Demo.java:20) Caused by: Exception [EclipseLink-25003] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.XMLMarshalException Exception Description: An error occurred marshalling the object Internal Exception: java.lang.NullPointerException at org.eclipse.persistence.exceptions.XMLMarshalException.marshalException(XMLMarshalException.java:78) at org.eclipse.persistence.oxm.XMLMarshaller.marshal(XMLMarshaller.java:516) at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:312) ... 1 more Caused by: java.lang.NullPointerException at org.eclipse.persistence.oxm.record.OutputStreamRecord.outputStreamWrite(OutputStreamRecord.java:511) at org.eclipse.persistence.oxm.record.FormattedOutputStreamRecord.openStartElement(FormattedOutputStreamRecord.java:84) at org.eclipse.persistence.internal.oxm.XPathNode.startElement(XPathNode.java:330) at org.eclipse.persistence.internal.oxm.XMLCompositeObjectMappingNodeValue.marshalSingleValue(XMLCompositeObjectMappingNodeValue.java:185) at org.eclipse.persistence.internal.oxm.XMLCompositeObjectMappingNodeValue.marshal(XMLCompositeObjectMappingNodeValue.java:116) at org.eclipse.persistence.internal.oxm.NodeValue.marshal(NodeValue.java:104) at org.eclipse.persistence.internal.oxm.record.ObjectMarshalContext.marshal(ObjectMarshalContext.java:60) at org.eclipse.persistence.internal.oxm.XPathNode.marshal(XPathNode.java:322) at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:325) at org.eclipse.persistence.internal.oxm.XMLCompositeObjectMappingNodeValue.marshalSingleValue(XMLCompositeObjectMappingNodeValue.java:176) at org.eclipse.persistence.internal.oxm.XMLCompositeObjectMappingNodeValue.marshal(XMLCompositeObjectMappingNodeValue.java:116) at org.eclipse.persistence.internal.oxm.NodeValue.marshal(NodeValue.java:104) at org.eclipse.persistence.internal.oxm.record.ObjectMarshalContext.marshal(ObjectMarshalContext.java:60) at org.eclipse.persistence.internal.oxm.XPathNode.marshal(XPathNode.java:322) at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:325) at org.eclipse.persistence.oxm.XMLMarshaller.marshal(XMLMarshaller.java:932) at org.eclipse.persistence.oxm.XMLMarshaller.marshal(XMLMarshaller.java:486) ... 2 more