Skip to content
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

How to call rest.get("some url") with header #36

Open
wureka opened this issue Mar 9, 2015 · 1 comment
Open

How to call rest.get("some url") with header #36

wureka opened this issue Mar 9, 2015 · 1 comment

Comments

@wureka
Copy link

wureka commented Mar 9, 2015

Hi,
My code is as below:

def getUser(String mid) {
    String HTTPS_URL_GET_USERS = "https://channel-apis.line.naver.jp/v1/profiles?mids=%s"
    def rest = new RestBuilder()
    log.debug("URL = " + String.format(HTTPS_URL_GET_USERS, mid))
    def resp = rest.get(String.format(HTTPS_URL_GET_USERS, mid)) {
        header 'X-Line-ChannelToken', LINE_ACCESS_TOKEN
        contentType "application/json; charset=UTF-8"
    }
    log.debug("user: ${resp.responseEntity.body}")
    def obj = grails.converters.JSON.parse(resp.responseEntity.body)
    return obj
}

When I call this method, the below exception occurs:

Can not deserialize instance of java.lang.String out of START_OBJECT token
 at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@3ac467f3; line: 1, column: 1]. Stacktrace follows:
com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
 at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@3ac467f3; line: 1, column: 1]
    at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)
    at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:749)
    at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:59)
    at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:12)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3051)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2206)
    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.get(RestBuilder.groovy:113)
    at com.fet.ebu.imsghub.service.LineService$$EP6OF3Sl.$tt__getUser(LineService.groovy:104)
    at com.fet.ebu.imsghub.v1.LineController.index(LineController.groovy:20)
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:198)
    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:745)

Would you please help me to solve the problem ?
Thank you

@atapin
Copy link

atapin commented Oct 5, 2015

@wureka I worked it around with adding accept JSONObject into the builder customizer. After that I can read resp.body as a JSONObject. Working on deserializing response to prepared POGOs now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants