Greetings,
I am having trouble with the current REST WS version (v2.4) when attempting to convert classes that have generic superclasses. The issue I am running into is that when a property setter method is generic and defined in the base class, the type defined by the child class is not being used for the parameter type. Instead, the TypeVariable (ie, <T>) is attempted to be used and failing. The issue appears to be in the BaseDelegatingResource.setProperty (lines 697-698) and the ConversionUtil.convert (lines 87-88) methods.
I have finally figured out what (I think) is going on and I only sort of understand that description above so here is a contrived example that shows what I mean. Given these classes:
public abstract class BaseClass<T> {
private T something;
public T getSomething() { return something; }
public void setSomething(T something) { this.something = something; }
}
public class ChildClass extends BaseClass<Integer> {
}
The type that should be found when attempting to set the 'setSomething' property for the ChildClass class should be Integer. Instead, BaseDelegatingResource.setProperty will find the TypeVariable <T> and pass that as the toType parameter of the ConversionUtil.convert method which then promptly blows up.
From BaseDelegatingResource.setProperty (lines 697-698):
Method setter = PropertyUtils.getPropertyDescriptor(instance, propertyName).getWriteMethod(); // Properly returns setSomething Method
value = ConversionUtil.convert(value,setter.getGeneraticParameterTypes()[0]); // Bolded code returns TypeVariable, not ParameterizedType
The potential for this kind of problem is noted in
this article along is a rather cumbersome solution but I wanted to check if this was a known issue and, if not, start the discussion about a fix.
Thanks,
-Wes Brown