Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 338711

Summary: JAXBElement<Object> with XmlElementRef fails to unmarshal and marshals with no type attribute
Product: z_Archived Reporter: Matt MacIvor <matt.macivor>
Component: EclipselinkAssignee: 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   
Whiteboard:
Attachments:
Description Flags
Propsed fix none

Description Matt MacIvor CLA 2011-03-02 13:01:22 EST
Given a class with the following property:
    @XmlElementRef(name = "inObject", type = JAXBElement.class, required = false)
    protected JAXBElement<Object> inObject;

When marshalling, the xsi:type is omitted:
<ns0:echoAnyType xmlns:ns0="urn:test:types"><inObject>foo</inObject></ns0:echoAnyType>

The correct document should contain an xsi:type="xsd:string" attribute on the inObject element.

When unmarshalling, if the xsi:type attribute is present, and exception is thrown:
org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Trying to set value
[javax.xml.bind.JAXBElement@787c16] for instance variable [inObject] of type
[javax.xml.bind.JAXBElement] in the object.  The specified object is not an
instance of the class or interface declaring the underlying field, or an
unwrapping conversion has failed.
Internal Exception: java.lang.IllegalArgumentException: Can not set
javax.xml.bind.JAXBElement field
fromwsdl.wsdl_hello_lit.client.EchoAnyType.inObject to java.lang.String
Mapping:
org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping[inObject]
Descriptor: XMLDescriptor(fromwsdl.wsdl_hello_lit.client.EchoAnyType -->
[DatabaseTable(ns0:echoAnyType)])
        at
org.eclipse.persistence.exceptions.DescriptorException.illegalArgumentWhileSet
tingValueThruInstanceVariableAccessor(DescriptorException.java:700)
        at
org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor
.setAttributeValueInObject(InstanceVariableAttributeAccessor.java:188)
        at
org.eclipse.persistence.mappings.foundation.AbstractCompositeObjectMapping.set
AttributeValueInObject(AbstractCompositeObjectMapping.java:187)
        at
org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping.setAttributeVal
ueInObject(XMLCompositeObjectMapping.java:763)
Comment 1 Matt MacIvor CLA 2011-03-02 14:47:21 EST
Created attachment 190193 [details]
Propsed fix
Comment 2 Matt MacIvor CLA 2011-03-04 10:04:36 EST
Attached patch checked in to SVN
Reviewed by David McCann
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:16:11 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:33:55 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink