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

Bug 322183

Summary: NullPolicy & element with just attributes producing null
Product: z_Archived Reporter: Blaise Doughan <blaise.doughan>
Component: EclipselinkAssignee: Blaise Doughan <blaise.doughan>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipselink.oxm-inbox
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Core - Fix
none
Core - Fix
none
MOXy - Test Cases
none
Core - Fix
none
MOXy - Test Cases
none
Core - Fix
none
MOXy - Test Cases none

Description Blaise Doughan CLA 2010-08-09 16:08:33 EDT
Given the following class:

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.eclipse.persistence.oxm.annotations.XmlMarshalNullRepresentation;
import org.eclipse.persistence.oxm.annotations.XmlNullPolicy;

@XmlRootElement(name="RootEntity")
public class RootEntity {

    @XmlElement(name="EntityOne")
    @XmlNullPolicy(emptyNodeRepresentsNull=true, nullRepresentationForXml=XmlMarshalNullRepresentation.EMPTY_NODE)
    public Entity entityOne;

    @XmlElement(name="EntityTwo")
    @XmlNullPolicy(emptyNodeRepresentsNull=true, nullRepresentationForXml=XmlMarshalNullRepresentation.EMPTY_NODE)
    public Entity entityTwo;

}

And the following XML:

<RootEntity> 
    <EntityOne id="objectID"/> 
    <EntityTwo /> 
</RootEntity> 

The corresponding object unmarshalled should have the entityOne property set to an instance of Entity, and entityTwo set to null.  Currently both are set to null.

This only happens if there are no sub-elements.
Comment 1 Blaise Doughan CLA 2010-08-10 16:07:39 EDT
Created attachment 176279 [details]
Core - Fix
Comment 2 Blaise Doughan CLA 2010-08-11 10:28:47 EDT
Created attachment 176349 [details]
Core - Fix
Comment 3 Blaise Doughan CLA 2010-08-11 10:48:13 EDT
Created attachment 176357 [details]
MOXy - Test Cases
Comment 4 Blaise Doughan CLA 2010-08-11 11:42:23 EDT
Created attachment 176370 [details]
Core - Fix
Comment 5 Blaise Doughan CLA 2010-08-11 11:42:45 EDT
Created attachment 176371 [details]
MOXy - Test Cases
Comment 6 Blaise Doughan CLA 2010-08-11 13:29:57 EDT
Created attachment 176379 [details]
Core - Fix
Comment 7 Blaise Doughan CLA 2010-08-11 13:30:17 EDT
Created attachment 176380 [details]
MOXy - Test Cases
Comment 8 Blaise Doughan CLA 2010-08-11 14:58:11 EDT
Added a new event to DeferredContentHandler called processEmptyElementWithAttributes().  By default this just calls processEmptyElement.  This is overridden in CompositeObjectMappingContentHandler where it is treated as processComplexElement().  

The processEmptyElementWithAttributes event is called when there are no sub-elements or characters and atleast one attribute that is not a namespace declaration or in the xsi namespace.

Code checked into trunk at rev:  8026

Code reviewed by:  Matt MacIvor
Comment 9 Eclipse Webmaster CLA 2022-06-09 10:03:57 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink