How can I get a map of the key/values of only the user-defined properties on one of my domain objects?
Problem is if I do this myself, I get my properties plus class, metaClass, constraints, closures, etc...
I assume Grails can do this fairly easily because it is done at some level in the scaffold code right? How can I do this myself?
Try this
It also works if you use
alex.metaClass.surname = 'such'
. This property will be displayed in the each loopThis is an old question, but I just ran across this requirement and found another solution that is worth answering here for others who come across this thread. I have put together an example based on that thread:
Sample Bean
Test Class
The
SampleBean
I put a variety of fields to show that it works, this is the output of the println:I think the best way is to use .properties on a domain object to get map of the fields in grails , tested in grails 2.1