Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 336249 - Class property order doesn't allow superclass properties in it
Summary: Class property order doesn't allow superclass properties in it
Status: CLOSED INVALID
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Blaise Doughan CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-03 10:48 EST by Zdenek Farana CLA
Modified: 2022-06-09 10:08 EDT (History)
1 user (show)

See Also:


Attachments
MOXy - Test Cases (12.13 KB, patch)
2011-05-09 16:44 EDT, 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 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