Using Groovy 2.0
Just as background I am rolling Yaml with SnakeYaml into Groovy classes. SnakeYaml uses Java reflection to construct and invoke the setting of properties. I want to with certain classes (that are created from Yaml) to allow for the addition of simple properties that do not exist. Thought first about using Groovy get/setProperty on the class definition and dumping the contents into a map store. But since SnakeYaml uses reflection this don't work. Tried to override the utility responsible for setting properties:
def originalMethod = org.yaml.snakeyaml.introspector.PropertyUtils.metaClass.getMetaMethod("getProperty", Class, String)
org.yaml.snakeyaml.introspector.PropertyUtils.metaClass.getProperty = { Class type, String name ->
// do stuff, like create the property on the metaClass
def result = originalMethod.invoke(delegate, type, name)
result
}
But the overridden "getProperty" method never gets called. Ideas? Is it better to use a proxy interceptor? The footprint of the "getProperty" method is:
public Property getProperty(Class<? extends Object> type, String name)
throws IntrospectionException {
return getProperty(type, name, beanAccess);
}