Issue Details (XML | Word | Printable)

Key: GDS-181
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Franck Wolff
Reporter: Archie Chen
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
GraniteDS

GDS-173 has other problem about generic type.

Created: 13/Aug/08 05:00 AM   Updated: 13/Aug/08 11:53 AM   Resolved: 13/Aug/08 11:42 AM
Component/s: AMF3 (de)serialization
Affects Version/s: 1.1.0_RC4
Fix Version/s: 1.1.0_GA

Environment:   windowsXP jdk1.6.0_07 Tomcat6.0.16 spring2.5.4 hibernate3.2.6
Issue Links:
Duplicate
 


 Description  « Hide
the code in Converter.java:

if (targetType instanceof TypeVariable) {
         TypeVariable<?> typeVariable = (TypeVariable<?>)targetType;
         if (typeVariable.getGenericDeclaration() instanceof Type)
         targetType = (Type)typeVariable.getGenericDeclaration();
}

the problem is "typeVariable.getGenericDeclaration()", this method returns the GenericDeclaration object representing the generic declaration declared this type variable. it's not true.

I think use "typeVariable.getBounds()" ,it's returns an array of Types representing the upper bound(s) of this type variable.

example entity code:

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Application<T extends ApplicationMeta> extends
AbstractEntity {

private static final long serialVersionUID = -5063254461237352117L;

private T applicationMeta;

@ManyToOne(fetch = FetchType.LAZY, targetEntity = ApplicationMeta.class)
@JoinColumn(name = "META_ID", nullable = false)
public T getApplicationMeta() {
return applicationMeta;
}

public void setApplicationMeta(T meta) {
this.applicationMeta = meta;
}
}

getGenericDeclaration returns Application,getBounds returns [ApplicationMeta],ApplicationMeta is expected.
 

Franck Wolff added a comment - 13/Aug/08 11:42 AM
This should be fixed now (GDS trunk).

ClassUtil.java:

    public static Type getBoundType(TypeVariable<?> typeVariable) {
     Type[] ubs = typeVariable.getBounds();
     if (ubs.length > 0)
     return ubs[0];
    
     // should never happen...
     if (typeVariable.getGenericDeclaration() instanceof Type)
     return (Type)typeVariable.getGenericDeclaration();
     return typeVariable;
    }

This method is used Converter.java & Converters.java.

Thanks!
Franck.