Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 322183 - NullPolicy & element with just attributes producing null
Summary: NullPolicy & element with just attributes producing null
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: Blaise Doughan CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-09 16:08 EDT by Blaise Doughan CLA
Modified: 2022-06-09 10:03 EDT (History)
1 user (show)

See Also:


Attachments
Core - Fix (2.25 KB, patch)
2010-08-10 16:07 EDT, Blaise Doughan CLA
no flags Details | Diff
Core - Fix (2.26 KB, patch)
2010-08-11 10:28 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Test Cases (4.35 KB, patch)
2010-08-11 10:48 EDT, Blaise Doughan CLA
no flags Details | Diff
Core - Fix (2.34 KB, patch)
2010-08-11 11:42 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Test Cases (4.90 KB, patch)
2010-08-11 11:42 EDT, Blaise Doughan CLA
no flags Details | Diff
Core - Fix (3.64 KB, patch)
2010-08-11 13:29 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Test Cases (6.88 KB, patch)
2010-08-11 13:30 EDT, Blaise Doughan CLA
no flags Details | Diff

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