-
Notifications
You must be signed in to change notification settings - Fork 32
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
This annoyed me! Expected a string but was BEGIN_OBJECT at line 1 column 2. #40
Comments
Great that it annoyed you, but please provide more information than this, we cannot possibly reproduce if you just paste a stack trace |
This is the code I tried it with.
I found a workaround, But, I still need a solution. Plus, the returned value's content type is not 'application/json' rather 'text/html;charset=utf-8' |
I've the same problem, any idea? |
Well, looking at the code I've found a solution def resp = rest.get('http://api.bigoven.com/recipes?pg=1&rpp=9&title_kw=cake&api_key=$api_key') { You must replace 'application/json' with JsonObject, I think that both ways should be supported. |
For the old behaviour, which will parse it into a
|
This works just fine for me:
So, not sure how to replicate. Can you please post a sample app that demonstrates the problem? |
Sure. The problem may be related to the fact that I'm unit testing with
And then overwrite/add these files: https://dl.dropboxusercontent.com/u/55056243/example.tar.gz. Update dependencies. In |
I believe I have fixed this with the information contained in: |
@matthijsbierman 's solution worked. I am closing the issue. |
Glad that it helped, but I don't believe you should have closed the issue already. There is still a problem, because it should work out of the box. It should only be closed once the bug is fixed upstream, as @bkoehm mentioned. |
I am re-openning. I spent time trying to cast the output to JSON and perform operations on the JSON but with out success. |
Use the new version of the underlying JAR to solve the problem:
|
@graemerocher, in Grails 2.5.3, updating the JAR results in this issue
I assume that's because the fix only applies to Grails 3.X. Any solution for 2.5.3 (short of refactoring a bunch of code per the workarounds above)? |
I'm having the same error on 2.5.2 using 2.0.0 version of the plugin. Below code reproduces the problem def resp = rest.post("https://www.google.com/recaptcha/api/siteverify") {
accept("application/json")
urlVariables secret:"asdfsdf", response: "lkjklj"
} |
@Omnipresent, the workaround mentioned above works on 2.5.x. Here's my snippet: RestBuilder rest = new RestBuilder()
//Workaround per https://github.com/grails-plugins/grails-rest-client-builder/issues/40
rest.restTemplate.messageConverters.removeAll {
it.class.name == 'org.springframework.http.converter.json.GsonHttpMessageConverter'
}
rest.post... |
@dustindclark Thanks, that works. For completeness sake RestBuilder rest = new RestBuilder()
rest.restTemplate.messageConverters.removeAll {
it.class.name == 'org.springframework.http.converter.json.GsonHttpMessageConverter'
}
def resp = rest.post("https://www.google.com/recaptcha/api/siteverify?secret=df&response="+params["g-recaptcha-response"])
def json = resp.json |
Remove org.springframework.http.converter.json.GsonHttpMessageConverter.
For others having this problem in grails 2.5.3: this workaround can be generalized by overwriting the default constructor for the RestBuilder.
|
hi |
Error 2015-07-09 13:30:22,849 [http-bio-8080-exec-4] ERROR errors.GrailsExceptionResolver - IllegalStateException occurred when processing request: [GET] /recipes-mashup/bigOven/batch
Expected a string but was BEGIN_OBJECT at line 1 column 2. Stacktrace follows:
Message: Expected a string but was BEGIN_OBJECT at line 1 column 2
Line | Method
->> 821 | nextString in com.google.gson.stream.JsonReader
| 358 | read in com.google.gson.internal.bind.TypeAdapters$13
| 346 | read . . . . . . . in ''
| 803 | fromJson in com.google.gson.Gson
| 768 | fromJson . . . . . in ''
| 312 | invokeRestTemplate in grails.plugins.rest.client.RestBuilder
| 273 | doRequestInternal in ''
| 261 | doRequestInternal in ''
| 106 | get . . . . . . . in ''
| 29 | getBatch in com.bonial.hackathon.services.BigOvenService
| 16 | batch . . . . . . in com.bonial.hackathon.BigOvenController
| 198 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter . . . . . in grails.plugin.cache.web.filter.AbstractFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
The text was updated successfully, but these errors were encountered: