New issue

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

Getting exception for content type application/json #23

Open
faridiflex opened this Issue Apr 15, 2014 · 2 comments

Comments

Projects
None yet
3 participants
@faridiflex

faridiflex commented Apr 15, 2014

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

This comment has been minimized.

Show comment
Hide comment
@ross-oreto

ross-oreto May 21, 2014

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

ross-oreto commented May 21, 2014

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

@brianbyers

This comment has been minimized.

Show comment
Hide comment
@brianbyers

brianbyers Jun 9, 2014

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"
}
}

brianbyers commented Jun 9, 2014

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"
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment