question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.lang.ClassCastException: com.google.gson.JsonSyntaxException cannot be cast to com.github.kittinunf.fuel.core.FuelError

See original GitHub issue

Suppose you have a JSON like

{
  "success": 1,
  "errors": [],
  "update_time": 1542190271,
}

And a parsing class like

data class YourResponse(
    val success: Int,
    val update_time: Int,
    val errors: ErrorsResponse?
) {
    data class ErrorsResponse(
        val data: List<String>?
    )

    class Deserializer : ResponseDeserializable<YourResponse> {
        override fun deserialize(content: String): YourResponse? =
            Gson().fromJson(content, YourResponse::class.java)
    }
}

If you parse this JSON in interactor like api.getJson().awaitObjectResponse(YourResponse.Deserializer()).third,

you will receive java.lang.ClassCastException: com.google.gson.JsonSyntaxException cannot be cast to com.github.kittinunf.fuel.core.FuelError,

while a real exception is com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 24 path $.errors.

It wastes much time to understand in a case of long JSON.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
SleeplessBytecommented, Nov 14, 2018

NikkyAI has fixed this after releasing 1.16.0.

You can either use jitpack to get the snapshot version, or wait for 2.0.0

On Wed, 14 Nov 2018, 12:51 A, notifications@github.com wrote:

@SleeplessByte https://github.com/SleeplessByte yes. Maybe I wrote too short, and some more information has been lost.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/kittinunf/Fuel/issues/531#issuecomment-438636269, or mute the thread https://github.com/notifications/unsubscribe-auth/AB35WJnnf-p3oOn1ooccvTHZK4xRYrm0ks5uvAO-gaJpZM4Yde1U .

1reaction
CoolMindcommented, Nov 14, 2018

@SleeplessByte yes. Maybe I wrote too short, and some more information has been lost.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[fuel-core] FuelError stacktrace is misleading #515 - GitHub
java.lang.ClassCastException: com.google.gson.JsonSyntaxException cannot be cast to com.github.kittinunf.fuel.core.FuelError #531.
Read more >
Could not initialize class com.github.kittinunf.fuel.core ...
I got errors when I call Fuel API but I couldn't realize what's wrong. My question: Does Fuel ... FuelManager] with root cause...
Read more >
What is the proper way to deserialize a List of things? #233
java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to io.smartly.balex.receiver.CommitStatus.
Read more >
fuel/FuelGson.kt at master · kittinunf/fuel - GitHub
import com.github.kittinunf.fuel.core.response. import com.google.gson.Gson. import com.google.gson.reflect.TypeToken. import java.io.Reader.
Read more >
Caused by: com.github.kittinunf.fuel.core.HttpException: HTTP ...
@SuppressLint("ShowToast") private fun getData(npa: String) { progressbar.visibility = View.VISIBLE val json = JSONObject() json.put("npa", ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found