Serve both GSP and JSON from Grails 3.1.5

I wanted my Grails 3.1.5 application to serve JSON data using the * .gson format. And for some pages / urls, I wanted to keep using GSP.

I created the application using the rest-api profile. Then I copied over the controllers and views from another application that I built using web-api.

At the same time, to be consistent, I also moved index.gson to another location.

Now I get a:

Could not resolve view with name 'index' in servlet with name 'grailsDispatcherServlet'

I started digging into viewResolvers, which are available in the 3.1.5 code base. Perhaps the rest-api profile configures viewResolver to search for * .gson files in a specific location.

Is it possible to configure, perhaps, a CompositeViewResolver that looks for both types, * .gson and * .gsps?

If so, how can I do this?

Thank!

+4
1

, build.gradle:

compile 'org.grails:grails-plugin-gsp'

profile 'org.grails.profiles:web'
profile 'org.grails.profiles:rest-api'

apply plugin: 'org.grails.grails-web'
apply plugin: 'org.grails.grails-gsp'
apply plugin: 'org.grails.plugins.views-json'

-, , REST, , HTML REST.

+3

All Articles