Skip to content

Instantly share code, notes, and snippets.

@jimwhite
Last active August 29, 2015 14:12
Show Gist options
  • Save jimwhite/396461b2df8f3448ee3e to your computer and use it in GitHub Desktop.
Save jimwhite/396461b2df8f3448ee3e to your computer and use it in GitHub Desktop.
Example of using a BeanInfo class for custom getter/setter names for Groovy properties.
class SomeBean {
private String _memo
String foo() { _memo }
void foo(String v) { _memo = v }
public static void main(String[] args) {
SomeBean bean = new SomeBean();
bean.foo = 'bar'
println bean.foo
}
}
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.beans.SimpleBeanInfo;
public class SomeBeanBeanInfo extends SimpleBeanInfo {
@Override
public PropertyDescriptor[] getPropertyDescriptors() {
try {
return new PropertyDescriptor[]{
new PropertyDescriptor("foo"
, SomeBean.class.getMethod("foo")
, SomeBean.class.getMethod("foo", String.class))};
} catch (IntrospectionException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment