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

Bug 328907

Summary: Binder issue with @XmlElements
Product: z_Archived Reporter: tibobd
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: NEW --- QA Contact:
Severity: major    
Priority: P3 CC: aumand, blaise.doughan, david.twelves, iaroslav.savytskyi, matt.macivor, sebastian.bosse
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description tibobd CLA 2010-10-28 03:56:11 EDT
Hi,

My eclipse link version is eclipselink-2.1.1.v20100817-r8050
My Java version is 1.6 u18

I try to use EclipseLink XML binder to keep xml comments. I try this sample http://bdoughan.blogspot.com/2010/09/jaxb-xml-infoset-preservation.html#comment-form, it works very fine.

But if i use @XmlElements in my class for example:

@XmlRootElement(name = "Customer")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "items"
})
public class Address {
     @XmlElements({
            @XmlElement(name="A", type=Integer.class),
            @XmlElement(name="B", type=Float.class)
        })
        public List items;
        //I remove get and set methods
}

When I call binder.updateXML method (to synchronise Java objects with my XML file), comments don't move, but tags moves after their root tag:
- Input XML:
<customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <address>
        <A>1</A>
        <!-- comments 2 -->
        <A>2</A>
    </address>
- Output XML:
<customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <address><A>1</A><A>2</A>
   
    <!-- comments 2 -->
       
   </address>

So there isn't synchronisation between my XML file and DOM, comments don't move, but tags moves !!! Tags musn't move. 

Thanks in advance for your help !

Tibo
Comment 1 Matt MacIvor CLA 2010-11-05 11:22:22 EDT
This is a bug with how EclipseLink handles a Node replace with XmlElements/ChoiceMappings. 

In the case of a choice it's very difficult to correctly replace all the possible choice elements with the contents of the new list, especially if the elements within the choice have different levels of nesting (configured via EclipseLink's @XmlPaths annotation) The JAXB RI, also fails to handle this, and when I run the same test with the RI, the comment is removed from the document. 

In EclipseLink the current support for Binder with a Choice will incorrectly remove and re-add the elements that match the choice. These elements will be added back in their correct position relative to other mapped content, but may end up in the wrong spot relative to unmapped content such as comments, processing instructions or other unmapped elements. This should be fixed to preserve the correct locations of the elements in question at least in the case that all possible choice elements are at the same level of nesting.

This bug will be targeted to be fixed in the 2.3 timeframe.
Comment 2 Sebastian Bosse CLA 2012-12-19 09:38:23 EST
I am facing exactely the same problem. When using @XmlElements the binder.updateXML() destroys my original order.

Short snippet of the model class:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "swservicerefOrSWSERVICEREFSYSCOND"
})
@XmlRootElement(name = "SW-SERVICE-REFS")
public class SWSERVICEREFS {

    @XmlElements({
        @XmlElement(name = "SW-SERVICE-REF-SYSCOND", type = SWSERVICEREFSYSCOND.class),
        @XmlElement(name = "SW-SERVICE-REF", type = SWSERVICEREF.class)
    })
...

Binder implementation is done as per exmaple: http://blog.bdoughan.com/2010/09/jaxb-xml-infoset-preservation.html

Looking forward to get a solution.

Thanks in advance.
Seb
Comment 3 Andreas A. CLA 2014-09-08 02:23:31 EDT
Hello.

This problem still persists with version 2.5.2.

My setup is slightly different (using XMLElementWrapper with XmlElementRef), but it boils down to a comparable schema:

<xs:complexType>
  <xs:sequence>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element ref="someRefA"/>
      <xs:element ref="someRefB"/>
    </xs:choice>
  </xs:sequence>
</xs:complexType>


what I try to achieve is:
- Parse the document (config file)
- unmarshall my domain object (using the Binder)
- change some values and
- save the file again, but keep the comments (and their relative positions to the nodes!).


Is there any fix for this problem yet?
Is there a better way to achieve my goal?
As this issue is quite old: is there any chance that this will be fixed some time in the near future?



Thanks in advance,

Andreas
Comment 4 Iaroslav Savytskyi CLA 2014-09-08 15:23:33 EDT
Hi Andreas,

Thank you for reminding us about this. We'll give a look. 
It looks like that this issue is quite complicated. :(
Comment 5 Sebastian Bosse CLA 2014-09-09 02:29:46 EDT
Hi.
For me it would also still be a big help, if it would be solved.
Luckily comments are not used often, but it occurs.

Would be great, if it would be taken up.

Regards,
Seb
Comment 6 Andreas A. CLA 2014-09-09 02:58:28 EDT
Hi Iaroslav,

thanks for the quick response.

I really appreciate your help. Unfortunately my configuration file will contain comments, so for me it is not acceptable to lose the proper ordering.

It would be a pitty, if I had to apply some "dirty workaround"...

Is there anything I can do, to increase the chances that this bug will finally be fixed after four years? Do you need a simplified example of my setup?


regards,

Andreas
Comment 7 Iaroslav Savytskyi CLA 2014-09-09 03:14:07 EDT
Hi Andreas,

I think the problem is quite visible with a given info. The bug has P3 priority. So we will start to work on it as soon as we will have resources.

Thanks.
Comment 8 Eclipse Webmaster CLA 2022-06-09 10:35:45 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink