Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 338711 - JAXBElement<Object> with XmlElementRef fails to unmarshal and marshals with no type attribute
Summary: JAXBElement<Object> with XmlElementRef fails to unmarshal and marshals with n...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-02 13:01 EST by Matt MacIvor CLA
Modified: 2022-06-09 10:33 EDT (History)
0 users

See Also:


Attachments
Propsed fix (3.01 KB, patch)
2011-03-02 14:47 EST, Matt MacIvor CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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