We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This plugin is great, but I'm not quite sure how to use it with the withFormat grails block.
withFormat
In particular, I'm looking at this from the standpoint of versioning a REST api via mime-types, similar to how Github does it.
Here is a rough idea of the sort of use pattern / setup I envision:
Config.groovy
// ... snip ... grails.mime.types = [html: ['text/html', 'application/xhtml+xml'], text: 'text/plain', js: 'text/javascript', rss: 'application/rss+xml', atom: 'application/atom+xml', css: 'text/css', csv: 'text/csv', all: '*/*', form: 'application/x-www-form-urlencoded', multipartForm: 'multipart/form-data', jsonv3:['application/vnd.myapp','application/vnd.myapp+json','application/vnd.myapp.v3+json'], // Default, default json, and v3 json jsonv2:['application/vnd.myapp.v2+json'], // Only v2 json xmlv3:['application/vnd.myapp+xml','application/vnd.myapp.v3+xml'], // Default xml, and v3 xml xmlv2:['application/vnd.myapp.v2+xml'] // only v2 xml ] // Having to declare this once for XML and once for JSON feels clunky grails.plugins.marshallers.xml = { v2{ } } grails.plugins.marshallers.json= { v2{ } } // ... snip ...
FooController.groovy
// ... snip ... def show() { def object = Foo.get(params.id) withFormat { html {object} jsonv3 { render fooInstance as JSON} // v3 is the default jsonv2 { JSON.use('v2') {render fooInstance as JSON} } xmlv3{ render fooInstance as XML} // v3 is the default xmlv2{ JSON.use('v2') {render fooInstance as XML} } } } // ... snip ...
FooV2XmlMarshaller
import org.codehaus.groovy.grails.web.converters.marshaller.ObjectMarshaller class FooV2XmlMarshaller implements ObjectMarshaller<XML> { static configuration = "v2" boolean supports(Object object) { Foo.isAssignableFrom(object.class) } void marshalObject(obj, xml) { // Special v2 stuff } }
Now, it might be that the plugin already enables this, which would be fantastic, but when I tried it myself, it didn't seem to want to work.
The text was updated successfully, but these errors were encountered:
Sorry for the late response.
As far as I know - the things should work as you described.
Could you provide me more details what does not work? In particular:
Sorry, something went wrong.
Merge pull request #1 from ajbrown/watched-resources
4d97a63
Re-initialize marshallers when a domain or config changes.
No branches or pull requests
This plugin is great, but I'm not quite sure how to use it with the
withFormat
grails block.In particular, I'm looking at this from the standpoint of versioning a REST api via mime-types, similar to how Github does it.
Here is a rough idea of the sort of use pattern / setup I envision:
Config.groovy
FooController.groovy
FooV2XmlMarshaller
Now, it might be that the plugin already enables this, which would be fantastic, but when I tried it myself, it didn't seem to want to work.
The text was updated successfully, but these errors were encountered: