I have a class with a getter and setter:
class A
{
private Set<Offers> offers;
public Set<Offers> getOffers(){
return offers;
}
public void setOffers(Set<Offers> offers){
this.offers = offers;
}
}
Now I wanted to get the size() of the offers using Apache Commons PropertyUtils:
PropertyUtils.getProperty(myAInstance, "offers.size");
This should basically do the same as:
myAInstance.getOffers().size();
But using the PropertyUtils doesn't work and gives me a:
java.lang.NoSuchMethodException: Unknown property 'size' on class 'class java.util.LinkedHashSet'
Using PropertyUtils to all getters and setters on other objects is working fine.
I suspect it is because the size() method of a Collection is not following the getXXX and setXXX bean convention.
Is there another way to use PropertyUtils / or BeanUtils (or anything else from Apache Commons) to call the size() method of my collection?
Thanks Christoph
PropertyUtils is named "PropertyUtils" for a reason. It works on the java beans conventions. The "size()" method does not conform to that convention, so you can't refer to it as a property.
Perhaps you're better of with a something like MVEL or GroovyScript which supports both property navigation and function invocation. Here's a sample for mvel which should work
Give it a try.