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

Bug 336249

Summary: Class property order doesn't allow superclass properties in it
Product: z_Archived Reporter: Zdenek Farana <zdenek.farana>
Component: EclipselinkAssignee: Blaise Doughan <blaise.doughan>
Status: CLOSED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: eclipselink.oxm-inbox
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
MOXy - Test Cases none

Description Zdenek Farana CLA 2011-02-03 10:48:15 EST
Build Identifier: 2.3.0-SNAPSHOT (20110202.060516-27)

If the class with superclass is annotated with @XmlType(propOrder={...}) and the propOrder contains superclass properties (important, not in the beginning, f.e. propOrder={"superclassProp","classProp",...,"classLastProp"} works), the following exception is thrown:

org.eclipse.persistence.exceptions.JAXBException
Exception Description: The property or field superclassProp was specified in propOrder but is not a valid property.

I traced the issue into AnnotationProcessor.validatePropOrderForInfo(TypeInfo info), more specifically

if (!nextPropName.equals(EMPTY_STRING) && !info.getPropertyNames().contains(nextPropName))

Apparently, superclass properties are not added into the class properties. Therefore, the IF statement above must fail.

I don't know if such behavior works for generating schema, but it doesn't work for the serialization.

I tried a workaround - overriding getter for the superclass property such as:

    @Override
    public String getSuperclassProp() {
        return super.getSuperclassProp();
    }

The exception is not thrown anymore but it still doesn't work (which makes sense because the superclass properties are not part of the class). In the case of simple classes, the propOrder is not applied, in not-so-simple classes it duplicates the superclass properties like:

<Class>
 <superClassProp>...</superClassProp>
 <classProp>...</classProp>
 ....
 <superClassProp>...</superClassProp> <!-- right position, but duplicated above -->
 ...

Reproducible: Always
Comment 1 Zdenek Farana CLA 2011-02-03 10:53:17 EST
I've just figured out a workaround. Removing @XmlElement annotation from superclass and instead place it on the overridden getter like this:

    @Override
    @XmlElement(name = "superClassProp")
    public boolean isInvalid() {
        return super.isInvalid();
    }

Then the propOrder is applied correctly.
Comment 2 Blaise Doughan CLA 2011-05-09 16:44:51 EDT
Created attachment 195145 [details]
MOXy - Test Cases
Comment 3 Blaise Doughan CLA 2011-05-10 11:08:43 EDT
MOXy is working as expected:

Scenario #1 - Parent class is marked with @XmlTrasient
If the parent class is marked with @XmlTransient then the parent's properties can be included in the @XmlType(propOrder={...}) setting.

Scenario #2 - Parent class is not marked with @XmlTransient
If the parent class is not marked with @XmlTransient then then the parent's properties can not be in propOrder set on the child class.  When inheritance is mapped the parents properties must appear before the childs properties.

A set of test cases have been checked in to verify this behaviour.
Comment 4 Blaise Doughan CLA 2011-05-10 11:38:21 EDT
Test cases checked into trunk at rev:  9340
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:08:08 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink