I am calling an api, it told me to use id as the endpoint path and the api will encode it to base36.
//const val id: Long = 68203991471
const val base36: String = "vbyw8mn"
interface ApiService {
@GET("v1/series/{id}")
suspend fun getWebtoonApi(@Path("id") id: Long = 68203991471): Response<WebtoonJson>
}
object RetrofitApi {
private val retrofit = Retrofit.Builder()
.baseUrl("https://api.mangaupdates.com/")
.addConverterFactory(GsonConverterFactory.create())
.build()
val retrofitApi: ApiService = retrofit.create(ApiService::class.java)
}
I tried to change the id to long and string, but it doesn't work.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.webtoon_gacha, PID: 27282
com.google.gson.JsonSyntaxException: java.lang.NumberFormatException: Expected an int but was 68203991471 at line 1 column 25 path $.series_id
at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:228)
at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:218)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:40)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27)
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:243)
at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:153)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
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)
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@c36cdc, Dispatchers.Main.immediate]
Caused by: java.lang.NumberFormatException: Expected an int but was 68203991471 at line 1 column 25 path $.series_id
at com.google.gson.stream.JsonReader.nextInt(JsonReader.java:1172)
at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:226)
... 11 more
Kotlin's Int max value is 10 digits, and 68203991471 is 11 digits, so it correctly throws exception. try Long return type for series_id field instead.