grails how to delete property from object
suppose I have MyClass domain class:
class MyClass {
String prop1
String prop2
String prop3
}
I wonder is there any way to delete for example prop1 property from M开发者_Go百科yClass object ?
The only way to actually delete the property is to remove it from the source file. However, you can make attempts to access the property exhibit the same behaviour as an attempt to access a non-existent property.
class MyClass {
String prop1
String prop2
String prop3
}
MyClass.metaClass {
// Intercept attempts to get the property
getProp1 = {-> throw new MissingPropertyException("can't get prop1")}
// Intercept attempts to set the property
setProp1 = {throw new MissingPropertyException("can't set prop1")}
}
精彩评论