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

Bug 333306

Summary: MOXy: Issues with Self Mappings and XPaths to same name
Product: z_Archived Reporter: David McCann <david.mccann>
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
test case
none
Core - Fix
none
Core - Fix
none
MOXy - Test Cases none

Description David McCann CLA 2010-12-29 10:18:01 EST
Given the following model classes:

@XmlRootElement(name="PaymentInf")
public class PaymentInf {
    @XmlPath("id/text()")
    public String id;
    @XmlPath(".")
    public Creditor creditor;
}


@XmlRootElement
public class Creditor {
    @XmlPath("id/text()")
    private String id;
}

And the following xml instance document:

<PaymentInf>
    <id>pmtid</id>
    <creditor>
        <id>frstId</id>
    </creditor>
</PaymentInf>

We would expect that, upon unmarshal, PaymentInf.id would be "pmtid" and Creditor.id would be "frstId".  However, this is not the case;  PaymentInf.id is "" and Creditor.id is "frstIdfrstId".
Comment 1 David McCann CLA 2010-12-29 10:38:26 EST
(In reply to comment #0)
> Given the following model classes:
> 
> @XmlRootElement(name="PaymentInf")
> public class PaymentInf {
>     @XmlPath("id/text()")
>     public String id;
>     @XmlPath(".")
>     public Creditor creditor;
> }
> 
> 
> @XmlRootElement
> public class Creditor {
>     @XmlPath("id/text()")
>     private String id;
> }
> 
> And the following xml instance document:
> 
> <PaymentInf>
>     <id>pmtid</id>
>     <creditor>
>         <id>frstId</id>
>     </creditor>
> </PaymentInf>
> 
> We would expect that, upon unmarshal, PaymentInf.id would be "pmtid" and
> Creditor.id would be "frstId".  However, this is not the case;  PaymentInf.id
> is "" and Creditor.id is "frstIdfrstId".

Should be:

public class Creditor {
    @XmlPath("creditor/id/text()")
    private String id;
}
Comment 2 David McCann CLA 2010-12-29 10:39:30 EST
Workarounds:

1) rename one or more 'id' field XPaths such that the are different.
2) map one of the 'id' fields to an attribute.
Comment 3 David McCann CLA 2010-12-29 11:07:49 EST
Created attachment 185878 [details]
test case
Comment 4 Blaise Doughan CLA 2011-01-10 13:48:09 EST
Created attachment 186411 [details]
Core - Fix
Comment 5 Blaise Doughan CLA 2011-01-10 16:25:28 EST
Created attachment 186432 [details]
Core - Fix
Comment 6 Blaise Doughan CLA 2011-01-11 16:07:59 EST
Created attachment 186567 [details]
MOXy - Test Cases
Comment 7 Blaise Doughan CLA 2011-01-11 16:32:57 EST
Fix checked into trunk at rev:  8802

Code reviewed by:  David McCann

Normally during an unmarshal when unmapped content is found, an unmapped content handler is set on the XMLReader.  When the marshal record has self records this can not occur.  In these cases a flag has been added to UnmarshalRecord to keep track of being in an unmapped state, this is done by level.
Comment 8 Blaise Doughan CLA 2011-03-24 15:56:16 EDT
Fix checked into 2.2.1 at rev:  9168
Comment 9 Eclipse Webmaster CLA 2022-06-09 10:09:11 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink