Last active
August 29, 2015 14:12
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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