Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix for GRAILS-9513 "Hibernate Mapping Domain classes are not treated…

… the same as Domain classes found in domain folder"
  • Loading branch information...
commit 4e3a97778a9ae6c9b125d1e8bb07ad71fefa8ab9 1 parent 5758d4b
@graemerocher graemerocher authored
View
23 ...-converters/src/main/groovy/org/codehaus/groovy/grails/plugins/converters/ConvertersPluginSupport.groovy
@@ -28,6 +28,9 @@ import org.springframework.validation.Errors
import org.springframework.validation.BeanPropertyBindingResult
import grails.validation.ValidationErrors
import org.grails.datastore.mapping.validation.ValidationErrors
+import groovy.transform.CompileStatic
+import org.codehaus.groovy.grails.commons.GrailsDomainClass
+import grails.artefact.Enhanced
/**
* @author Graeme Rocher
@@ -41,18 +44,34 @@ class ConvertersPluginSupport {
* @param application
* @param applicationContext
*/
+ @CompileStatic
static void enhanceApplication(GrailsApplication application, ApplicationContext applicationContext) {
MetaClassEnhancer enhancer = new MetaClassEnhancer()
enhancer.addApi(new ConvertersApi(applicationContext:applicationContext))
// Override GDK asType for some common Interfaces and Classes
- enhancer.enhanceAll([Errors,BeanPropertyBindingResult, ValidationErrors, ValidationErrors, ArrayList, TreeSet, HashSet, List, Set, Collection, GroovyObject, Object, Enum].collect {
- GrailsMetaClassUtils.getExpandoMetaClass(it)
+ enhancer.enhanceAll([Errors,BeanPropertyBindingResult, ValidationErrors, ValidationErrors, ArrayList, TreeSet, HashSet, List, Set, Collection, GroovyObject, Object, Enum].collect { Class c ->
+ GrailsMetaClassUtils.getExpandoMetaClass(c)
})
+
+ enhanceRequest()
+ enhanceDomainClasses(application, enhancer)
+ }
+
+ static void enhanceDomainClasses(GrailsApplication grailsApplication, MetaClassEnhancer metaClassEnhancer) {
+ for(GrailsDomainClass dc in grailsApplication.domainClasses) {
+ if(!dc.getClazz().getAnnotation(Enhanced)) {
+ metaClassEnhancer.enhance(dc.metaClass)
+ }
+ }
+ }
+
+ private static void enhanceRequest() {
// Methods for Reading JSON/XML from Requests
def getXMLMethod = { -> XML.parse((HttpServletRequest) delegate) }
def getJSONMethod = { -> JSON.parse((HttpServletRequest) delegate) }
+
def requestMc = GroovySystem.metaClassRegistry.getMetaClass(HttpServletRequest)
requestMc.getXML = getXMLMethod
requestMc.getJSON = getJSONMethod
Please sign in to comment.
Something went wrong with that request. Please try again.