Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 354130 - Incorrect namespace generated for @XmlPath and @XmlAttribute are present for an attribute
Summary: Incorrect namespace generated for @XmlPath and @XmlAttribute are present for ...
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: Denise Smith CLA
QA Contact:
URL: http://stackoverflow.com/questions/69...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-08 09:23 EDT by Blaise Doughan CLA
Modified: 2022-06-09 10:05 EDT (History)
2 users (show)

See Also:


Attachments
Code demonstrating the bug (1.38 KB, application/x-zip-compressed)
2011-08-08 09:24 EDT, Blaise Doughan CLA
no flags Details
Proposed changes and tests (20.88 KB, patch)
2011-08-08 14:45 EDT, Denise Smith 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 2011-08-08 09:23:26 EDT
Given the following class:

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

import org.eclipse.persistence.oxm.annotations.XmlPath;

@XmlRootElement
public class FooBar {
    @XmlAttribute
    @XmlPath("test/@foo")
    private boolean foo;
}

The following incorrect schema is generated:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:ns0="http://moxy.test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://moxy.test" elementFormDefault="qualified">
   <xsd:complexType name="fooBar">
      <xsd:sequence>
         <xsd:element name="test" minOccurs="0">
            <xsd:complexType>
               <xsd:sequence/>
               <xsd:attribute ref="ns0:foo"/>
            </xsd:complexType>
         </xsd:element>
      </xsd:sequence>
   </xsd:complexType>
   <xsd:element name="fooBar" type="ns0:fooBar"/>
   <xsd:attribute name="foo" type="xsd:boolean" use="required"/>
</xsd:schema>

WORKAROUND:

If we remove the @XmlAttribute Annotation:

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

import org.eclipse.persistence.oxm.annotations.XmlPath;

@XmlRootElement
public class FooBar {
    //@XmlAttribute
    @XmlPath("test/@foo")
    private boolean foo;
}

Then the correct XML schema is generated:

class org.eclipse.persistence.jaxb.JAXBContext
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:ns0="http://moxy.test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://moxy.test" elementFormDefault="qualified">
   <xsd:complexType name="fooBar">
      <xsd:sequence>
         <xsd:element name="test" minOccurs="0">
            <xsd:complexType>
               <xsd:sequence>
                  <xsd:element name="@foo" type="xsd:boolean"/>
               </xsd:sequence>
            </xsd:complexType>
         </xsd:element>
      </xsd:sequence>
   </xsd:complexType>
   <xsd:element name="fooBar" type="ns0:fooBar"/>
</xsd:schema>
Comment 1 Blaise Doughan CLA 2011-08-08 09:24:24 EDT
Created attachment 201078 [details]
Code demonstrating the bug
Comment 2 Blaise Doughan CLA 2011-08-08 10:40:21 EDT
CORRECTION

The workaround is not valid as it produces:

     <xsd:element name="@foo" type="xsd:boolean"/>
Comment 3 Denise Smith CLA 2011-08-08 14:45:46 EDT
Created attachment 201098 [details]
Proposed changes and tests
Comment 4 Denise Smith CLA 2011-08-08 15:56:00 EDT
Fixed in 2.3 and 2.4.
Modified AnnotationsProcessor - the processing of XmlPath annotation was not allowing for the XmlPath to be to an attribute.

Also changed behavior so that if an @XmlAttribute was specified by the XmlPath was to an element the XmlPath annotation "wins".
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:05:58 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink