Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

JSON error with a bad wireless connection #888

Description

@GerardPaligot

Hello,

I'm developing an GitHub application with AndroidAnnotations. This application isn't very complex and all works fine except when I don't have a good wireless connection on my smartphone.

With this bad connection, I receive a force closed exception with a online request. After that, I won't be able to succeed this request again. I restart the application but the exception come back.

I'm using the GitHub API v3. So, there aren't problems with the JSON.

The stack trace is :

01-14 22:35:16.082: E/AndroidRuntime(9317): FATAL EXCEPTION: pool-1-thread-1
01-14 22:35:16.082: E/AndroidRuntime(9317): Process: fr.univ.lille1.github, PID: 9317
01-14 22:35:16.082: E/AndroidRuntime(9317): org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 13; nested exception is com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 13
01-14 22:35:16.082: E/AndroidRuntime(9317):     at org.springframework.http.converter.json.GsonHttpMessageConverter.readInternal(GsonHttpMessageConverter.java:143)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:147)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:76)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:655)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:641)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:484)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:447)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:422)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at fr.univ.lille1.github.network.RestGithub_.getFollowings(RestGithub_.java:55)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at fr.univ.lille1.github.FollowingActivity.backgroundRepository(FollowingActivity.java:36)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at fr.univ.lille1.github.FollowingActivity_.access$101(FollowingActivity_.java:27)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at fr.univ.lille1.github.FollowingActivity_$3.execute(FollowingActivity_.java:130)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at org.androidannotations.api.BackgroundExecutor$Task.run(BackgroundExecutor.java:302)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at java.lang.Thread.run(Thread.java:841)
01-14 22:35:16.082: E/AndroidRuntime(9317): Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 13
01-14 22:35:16.082: E/AndroidRuntime(9317):     at com.google.gson.Gson.fromJson(Gson.java:806)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at com.google.gson.Gson.fromJson(Gson.java:734)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at org.springframework.http.converter.json.GsonHttpMessageConverter.readInternal(GsonHttpMessageConverter.java:140)
01-14 22:35:16.082: E/AndroidRuntime(9317):     ... 19 more
01-14 22:35:16.082: E/AndroidRuntime(9317): Caused by: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 13
01-14 22:35:16.082: E/AndroidRuntime(9317):     at com.google.gson.stream.JsonReader.expect(JsonReader.java:339)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:306)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:79)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:60)
01-14 22:35:16.082: E/AndroidRuntime(9317):     at com.google.gson.Gson.fromJson(Gson.java:795)
01-14 22:35:16.082: E/AndroidRuntime(9317):     ... 21 more

Activity

  1. DayS commented on Jan 14, 2014

    @DayS
    Contributor

    Hi,

    I'm using the GitHub API v3. So, there aren't problems with the JSON.

    Yep, but I think the problem is in your DTO because of this error Expected BEGIN_ARRAY but was STRING at line 1 column 13

  2. GerardPaligot commented on Jan 14, 2014

    @GerardPaligot
    Author

    Yes, I thought that too but I can launch my online request without problems when I have a good connection.

  3. Artyomcool commented on Jan 15, 2014

    @Artyomcool

    Anyway, if the data is wrong AA should provide a graceful fallback - some
    way to handle this situation, what do you think?
    15.01.2014 1:45 ÐÏÌØÚÏ×ÁÔÅÌØ "Gerard" notifications@github.com ÎÁÐÉÓÁÌ:

    Yes, I thought that too but I can launch my online request without
    problems when I have a good connection.

    Reply to this email directly or view it on GitHubhttps://github.com//issues/888#issuecomment-32310779
    .

  4. DayS commented on Jan 15, 2014

    @DayS
    Contributor

    @Artyomcool > There is already a workaround for this since AA 3.0. Unfortunately it's partly buggy... But it will work

    Each rest methods implementation try to propagate the exception to a RestErrorHandler. So, the Rest interface just have to extends RestClientErrorHandling to be able to set this RestErrorHandler. Look at the generated code for this.
    Also, it seems I forgot to explain this point in the wiki.

    @GerardPaligot > This is weird because in case of bad connection, RestTemplate will eventually throw a IOException: Connection reset by peer and the converter will not try to deserialize the content. You best shot is to launch your app in debug and see what's going on.

  5. GerardPaligot commented on Jan 15, 2014

    @GerardPaligot
    Author

    I'll make some tests in debug mode. I'll keep you informed as soon as possible.

  6. yDelouis commented on Jun 8, 2014

    @yDelouis
    Contributor

    Any news on that ? Can the issue be closed ?

  7. DayS commented on Jun 8, 2014

    @DayS
    Contributor

    I'm closing this one as a fix may be provided with the merged PR and this issue starts to be old

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions