cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

BadResponseException: Bad JSON

BadResponseException: Bad JSON

Kevin H.27
New member | Level 1

Dear Dropbox Community,

I am using the Dropbox API v2 for my Android app. Lately I have been seeing issues when trying to download a file with client.files().download() where the file does not (yet) exist. Instead of the expected DownloadErrorException, I am getting a BadResponseException (full stack below). I am using the SDK as in compile 'com.dropbox.core:dropbox-core-sdk:2.0.2'

Any ideas?

com.dropbox.core.BadResponseException: Bad JSON: No suitable constructor found for type [simple type, class com.dropbox.core.DbxRequestUtil$ErrorWrapper$ApiErrorResponse<com.dropbox.core.v2.files.DownloadError>]: can not instantiate from JSON object (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: buffer(com.android.okhttp.internal.http.HttpConnection$ChunkedSource@87dfad0).inputStream(); line: 1, column: 2]
at com.dropbox.core.v2.DbxRawClientV2$2.execute(DbxRawClientV2.java:157)
at com.dropbox.core.v2.DbxRawClientV2$2.execute(DbxRawClientV2.java:129)
at com.dropbox.core.v2.DbxRawClientV2.executeRetriable(DbxRawClientV2.java:238)
at com.dropbox.core.v2.DbxRawClientV2.downloadStyle(DbxRawClientV2.java:129)
at com.dropbox.core.v2.files.DbxUserFilesRequests.download(DbxUserFilesRequests.java:258)
at com.dropbox.core.v2.files.DbxUserFilesRequests.download(DbxUserFilesRequests.java:284)
at com.podcatcher.deluxe.model.sync.dropbox.DropboxPodcastListSyncController$DropboxSyncPodcastListTask.getServerSubscriptions(DropboxPodcastListSyncController.java:187)
at com.podcatcher.deluxe.model.sync.dropbox.DropboxPodcastListSyncController$DropboxSyncPodcastListTask.doInBackground(DropboxPodcastListSyncController.java:104)
at com.podcatcher.deluxe.model.sync.dropbox.DropboxPodcastListSyncController$DropboxSyncPodcastListTask.doInBackground(DropboxPodcastListSyncController.java:88)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class com.dropbox.core.DbxRequestUtil$ErrorWrapper$ApiErrorResponse<com.dropbox.core.v2.files.DownloadError>]: can not instantiate from JSON object (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: buffer(com.android.okhttp.internal.http.HttpConnection$ChunkedSource@87dfad0).inputStream(); line: 1, column: 2]
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1130)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:298)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:133)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3789)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2863)
at com.dropbox.core.DbxRequestUtil$ErrorWrapper.fromResponse(DbxRequestUtil.java:273)
at com.dropbox.core.v2.DbxRawClientV2$2.execute(DbxRawClientV2.java:152)
... 13 more

 

11 Replies 11

Greg-DB
Dropbox Staff

Thanks for the report! I can't seem to reproduce this issue. Can you let me know about when you started seeing it, and about what percent of calls fail like this, to the best of your knowledge? Does it only happen for certain file paths? Thanks in advance!

Kevin H.27
New member | Level 1

Gergory, thanks for your reply!

I have a podcast app which has multiple variants, all using the "App folder" permission. I see this problem consistently now for all the variants and I think that the same code worked last week. My steps are quite simple:

0. Unlink app and delete app folder to reset

1. Connect app using the AuthActivity

2. Try to download "/Subscriptions.txt" with client.files().download()

From the debugging I can see that the correct request is send and that the server returns a status code of 409 (probably okay since the file does not yet exist). The Dropbox SDK then tries to parse the response body as a JSON, and fails since it is empty. This results in a BadResponseException instead of the DownloadErrorException I am expecting. If I try the same query from the API Explorer, I get the correct answer:

{
  "error_summary": "path/not_found/..",
  "error": {
    ".tag": "path",
    "path": {
      ".tag": "not_found"
    }
  }
}

 

 

Greg-DB
Dropbox Staff

Thanks for following up. So, it sounds like you're seeing it for 100% of your calls to client.files().download()? Are other methods also failing, or are they working properly? 

I still can't seem to reproduce this though, even with the additional conditions you mentioned. Are your users seeing this issue too, or is it only happening for you?

Kevin H.27
New member | Level 1

Yes, I see this behaviour for 100% of my calls, if the file requested to download does not exist. If it does, everything works fine. All other calls I use also work fine.

As for users, I have no reports yet. But you could easily try it yourself, simply get my "Simple Podcatcher" app from Google Play and try to syncing via Dropbox. If you connect your device via adb, you should be able to see the error message.

Thanks for your help!

Greg-DB
Dropbox Staff

Thanks Kevin, that's helpful. I can reproduce the error using your app. Can you share the relevant code snippet(s)? We'll need to reproduce this separately, and there may be something different between your implementation and mine.

Kevin H.27
New member | Level 1

Sure, my app is Open Source. Please visit https://github.com/salema/Podcatcher-Deluxe-Android-Studio/blob/master/app/src/main/java/com/podcatc... to see the code, the relevant bit for the error starts at line 182, method getServerSubscriptions()

Thanks for taking the time to look into this!

Greg-DB
Dropbox Staff

That's very useful, thanks! We're looking into it.

Greg-DB
Dropbox Staff

Based on our investigation, you should be able to work around this issue by adding the following rule to your ProGuard configuration:

-keepclassmembers class com.dropbox.core.** { @com.fasterxml.jackson.annotation.JsonCreator *; }

We'll be addressing this issue in general in a future update of the SDK itself.

Kevin H.27
New member | Level 1

Thanks Gregory, that does the trick. I was following the ProGuard documentation on the SDK's website, so I ruled it out as a reason for this issue. Thanks for getting me back on track!

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Kevin H.27 New member | Level 1
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?