Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 333306 - MOXy: Issues with Self Mappings and XPaths to same name
Summary: MOXy: Issues with Self Mappings and XPaths to same name
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-12-29 10:18 EST by David McCann CLA
Modified: 2022-06-09 10:09 EDT (History)
1 user (show)

See Also:


Attachments
test case (2.37 KB, patch)
2010-12-29 11:07 EST, David McCann CLA
no flags Details | Diff
Core - Fix (2.48 KB, patch)
2011-01-10 13:48 EST, Blaise Doughan CLA
no flags Details | Diff
Core - Fix (2.45 KB, patch)
2011-01-10 16:25 EST, Blaise Doughan CLA
no flags Details | Diff
MOXy - Test Cases (7.67 KB, patch)
2011-01-11 16:07 EST, 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 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