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

Getting exception for content type application/json #23

Open faridiflex opened 10 years ago

faridiflex commented 10 years ago

Hi

I am getting the HttpMessageNotWritableException when I try to execute the following code:

def rest = new RestBuilder(connectTimeout:10000, readTimeout:20000) def resp = rest.post("http://requestb.in/1mhfid91"){ json { name = "test-group" description = "A temporary test group" } }

Please suggest if I am missing something.

Here is the Exception message:

org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: (was java.lang.NullPointerException) (through reference chain: grails.converters.JSON["depth"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: grails.converters.JSON["depth"]) at grails.plugins.rest.client.RestBuilder.invokeRestTemplate(RestBuilder.groovy:307) at grails.plugins.rest.client.RestBuilder.doRequestInternal(RestBuilder.groovy:280) at grails.plugins.rest.client.RestBuilder.doRequestInternal(RestBuilder.groovy:268) at grails.plugins.rest.client.RestBuilder.post(RestBuilder.groovy:154) at com.simpleinteract.util.UrlShortenerService$$EObVm8au.shortenUrl(UrlShortenerService.groovy:54) at Script1.run(Script1.groovy:14) at org.grails.plugins.console.ConsoleService.eval(ConsoleService.groovy:57) at org.grails.plugins.console.ConsoleService.eval(ConsoleService.groovy:37) at org.grails.plugins.console.ConsoleController$_closure2.doCall(ConsoleController.groovy:61) at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195) at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) Caused by: com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: grails.converters.JSON["depth"]) at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:232) at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:197) at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:183) at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:559) at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:143) at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:120) at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:1727) ... 14 more Caused by: java.lang.NullPointerException at grails.converters.JSON.getDepth(JSON.java:217) at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.get(BeanPropertyWriter.java:653) at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:509) at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:551) ... 17 more undefined

ross-oreto commented 10 years ago

I'm also getting this error using almost identical code.

brianbyers commented 10 years ago

Add in the contentType of json, I was having the same issue until I added that

def rest = new RestBuilder(connectTimeout:10000, readTimeout:20000) def resp = rest.post("http://requestb.in/1mhfid91"){ contentType "application/json" json { name = "test-group" description = "A temporary test group" } }