0

With my Grails 4.0.10 build my default JSON views throw a "NoSuchMethod" error with

grails.core.GrailsDomainClass.getIdentifier()Lgrails/core/GrailsDomainClassProperty

This error occurs from this simple Grails console example:

import grails.converters.JSON
def obj = Organization.get(122L)
obj as JSON

I have tried various builds to get rid of the error, including this:

compile 'org.grails.plugins:converters:4.0.0'

or not specifying anything, or let the version default to the latest. In the dependency-report I see these lines, which may be trying to tell me something:

    +--- org.grails:grails-datastore-rest-client -> 6.1.12.RELEASE
|    +--- org.codehaus.groovy:groovy:2.4.11 -> 2.5.14
|    +--- commons-codec:commons-codec:1.5 -> 1.11
|    +--- org.grails:grails-plugin-converters:3.2.11
|    |    +--- org.codehaus.groovy:groovy:2.4.11 -> 2.5.14
|    |    +--- org.slf4j:slf4j-api:1.7.22 -> 1.7.30
|    |    +--- org.slf4j:jcl-over-slf4j:1.7.22 -> 1.7.30 (*)
|    |    \--- commons-lang:commons-lang:2.6
|    +--- org.grails:grails-async:3.2.11 -> 4.0.0 (*)
|    +--- org.grails:grails-core:3.2.11 -> 4.0.10 (*)
|    \--- org.grails:grails-web:3.2.11 -> 4.0.10 (*)

and contributing from one of our plugins:

+--- org.grails.plugins:converters:4.0.0 -> 4.0.1 (*)

What do I need to do to get the JSON views working again after the upgrade from Grails 3.2.13?

Jay
  • 173
  • 10

2 Answers2

1

By default a Grails 4.0.10 project will have a dependency on compile "org.grails:grails-plugin-rest" (will be 4.0.10 by default if the build hasn't been modified) and that artifact has a transitive dependency on org.grails.plugins:converters:4.0.1.

Jeff Scott Brown
  • 26,804
  • 2
  • 30
  • 47
-1

The answer for my case, after much ado, build.gradle:

classpath 'org.grails.plugins:converters:4.0.1'

and

compile 'org.grails.plugins:converters:4.0.1'
Jay
  • 173
  • 10
  • That's a good short term answer, but as you have time, it would be good to start converting over to json views. Json views have much better performance. http://views.grails.org/latest/ – virtualdogbert Feb 25 '22 at 02:47
  • Why is it that you suggest `classpath 'org.grails.plugins:converters:4.0.1'`? – Jeff Scott Brown Feb 25 '22 at 15:24
  • "That's a good short term answer" - @virtualdogbert Is the `classpath` entry useful? – Jeff Scott Brown Feb 25 '22 at 18:18
  • @JeffScottBrown I just mean that using converters are a good short term answer, but pointing to json views as a better solution , as they have better performance, and would be better supported. I always saw the converter plugin as a stop gap on the way to upgrading to json views. Converting as JSON can be tedious in large apps and if you use the converts to render to a JSON string outside the context of a controller you have to do something like this: https://github.com/virtualdogbert/rest-docs/blob/master/grails-app/services/rest/docs/JsonTemplateService.groovy – virtualdogbert Feb 25 '22 at 21:05
  • Comment noted. In our apps JSON views are used extensively, but as you can see, not exclusively. The shorthand "respond" situations arise from older legacy controllers that have limited use. And yes, it should be upgraded - that is on a todo list, somewhere. – Jay Feb 26 '22 at 09:22
  • And yes, the classpath entry is not required. – Jay Feb 28 '22 at 13:37