Reputation: 4706
I would like to send some data with POST to my grails application.
I have got a really easy domain:
class Step {
String name;
Long taskId = -1;
static constraints = {
}
}
I implemented service for it:
@Path('/api/step')
class StepResource {
@POST
@Consumes(['application/json'])
String create(Step dto) {
// dto.save()
}
}
I added plugin to Google Chrome to test it - POSTMAN and try to POST.
The result is:
The grails console prints:
| Error 2013-06-08 23:30:25,574 [http-bio-8080-exec-3] ERROR container.ContainerRequest - A message body reader for Java class java.lang.Object, and Java type class java.lang.Object, and MIME media type application/json was not found.
The registered message body readers compatible with the MIME media type are:
application/json ->
com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$App
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$App
com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$App
*/* ->
com.sun.jersey.core.impl.provider.entity.FormProvider
com.sun.jersey.core.impl.provider.entity.StringProvider
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
com.sun.jersey.core.impl.provider.entity.FileProvider
com.sun.jersey.core.impl.provider.entity.InputStreamProvider
com.sun.jersey.core.impl.provider.entity.DataSourceProvider
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
com.sun.jersey.core.impl.provider.entity.ReaderProvider
com.sun.jersey.core.impl.provider.entity.DocumentProvider
com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
com.sun.jersey.core.impl.provider.entity.EntityHolderReader
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$General
com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General
Could you give me any solution ?
Upvotes: 1
Views: 783
Reputation: 12977
I am not sure you should print it.. just declare the string Also change the method type to String Also go over the documentation. It's the easiest approach https://github.com/krasserm/grails-jaxrs/wiki/Getting-Started
Upvotes: 1