grails-plugins / grails-rest-client-builder

REST client plugin that uses Spring's RestTemplate
http://grails.org/plugin/rest-client-builder
Apache License 2.0
65 stars 32 forks source link

JSON - No suitable HttpMessageConverter #13

Open IsidroGH opened 11 years ago

IsidroGH commented 11 years ago

Hi, I have a fresh new Grails project with rest-client-plugin 1.0.2 installed.

In a controller I execute the following (copied from the unit test):

def rest = new RestBuilder()

def builder = new JSONBuilder() JSON j = builder.build {name = "test-group"}

def resp = rest.put("http://localhost:8080/rest-1.0.0-SNAPSHOT/rest/entity/new"){ contentType "application/json" body j }

I always get the same error:

"Could not write request: no suitable HttpMessageConverter found for request type [grails.converters.JSON] and content type [application/json]"

Could you please tell me what can I do to solve it.

Thanks.

thu-nguyen commented 11 years ago

@dropy. Add this line to your code: j.toString()

def rest = new RestBuilder()

def builder = new JSONBuilder() JSON j = builder.build {name = "test-group"}

def resp = rest.put("http://localhost:8080/rest-1.0.0-SNAPSHOT/rest/entity/new"){ contentType "application/json" body j.toString() }

or you can do another way without JSONBuilder.

def rest = new RestBuilder() def j = {name = "test-group"}

def resp = rest.put("http://localhost:8080/rest-1.0.0-SNAPSHOT/rest/entity/new"){ contentType "application/json" json j }

or you can pass directly like this def resp = rest.put("http://localhost:8080/rest-1.0.0-SNAPSHOT/rest/entity/new"){ contentType "application/json" json { name = "test-group" } }