1
votes

I want to do reflexion on Domain associations to automatically generate a JSON/XML format class descriptor file for a RESTful WS (scaffolding).

Example domains are:

class Roof {
    Chimney chimney = new Chimney() 
    static embedded = ['chimney']
}

class Chimney {
    float height
}

I am using this code to know GORM class type:

GrailsDomainClassPersistentEntity entity = Roof.gormPersistentEntity

entity?.persistentProperties.each { PersistentProperty property ->
    Class<?> cl = property.getType()
}

When the property is an Association, the cl variable gets the class of the associated domain. This works perfectly when the association is a standard hasOne or hasMany. The problem I found is that, when the property is embedded, the type of class results in org.codehaus.groovy.grails.commons.DefaultGrailsDomainClassProperty.

I don't know another way to discover the class of that embebded property. Any posibilitity (embedded static attribute... etc.)?

edit:

Embedded e = property
e.getAssociatedEntity() //null
1

1 Answers

0
votes

check the value of embedded field of the domain class and scan the class properties' names for the matches