What I am wondering, is there a libarary for Java that allows you to determine the name of a property given an accessor/mutator.
Like so:
getValue() -> value
setAnotherValue(String v) -> anotherValue
I’m looking to use this property value with Apache BeanUtils to match the given setter/getter to the corresponding getter/setter respectively.
I know I’ve seen this behaviour before, but now that I am looking for it, I am unable to find a library that gives me this capabilty.
Thanks.
java.beans.Introspector is useful for getting that information. You want to use
getBeanInfo()then from the bean info, you typically want to callgetPropertyDescriptors()Using the property descriptor you can get the property names and then references tojava.lang.reflect.Methodobjects for the appropriate getters and setters if you wish to invoke them.Good luck.