Я получаю следующий URL-адрес от api
:
{"status":true,"ref":"urltogo","url":"http:\/\/myurl\/login\/index.php?testsession=55207"}
И здесь мое соединение api
:
mCompositeCommonDisposable.add(
login.getResultLogin("YYYY", "YYYY","/")
!!.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribeWith(object : DisposableObserver<Response<Login?>>() {
override fun onNext(loginResponse: Response<Login?>) {
if (loginResponse.isSuccessful) {
if (loginResponse.body() != null) {
loginModelApiResponseResultListener.onSuccess(
loginResponse.body()
)
} else {
loginModelApiResponseResultListener.onFailure(R.string.err_information)
}
} else {
loginModelApiResponseResultListener.onFailure(R.string.err_information)
}
}
override fun onError(e: Throwable) {
loginModelApiResponseResultListener.onFailure(R.string.fetching_data_failed)
}
override fun onComplete() {}
})
А вот мой interface
:
interface PublicApiTS {
@POST("/theme/fordson2/login")
fun getResultLogin(
@Query("username") username: String?,
@Query("password") password: String?,
@Query("returnurl") returnurl: String?
): Observable<Response<Login?>?>?
}
Но мне говорят:
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ c
А вот мой кастом object
:
@Entity(tableName = "Login")
data class Login (
@PrimaryKey(autoGenerate = true)
var id_login: Int = 0,
@SerializedName("status")
@Expose
val status: Boolean? = null,
@SerializedName("ref")
@Expose
val ref: String? = null,
@SerializedName("url")
@Expose
val url: String? = null
)
А вот мой модуль дооснащения:
@Module
class RemoteAPIDataModuleTS {
@Provides
fun provideGson(): Gson {
return GsonBuilder().setLenient().create()
}
@Provides
fun providePublicApi(retrofit: Retrofit): PublicApiTS {
return retrofit.create(PublicApiTS::class.java)
}
@Provides
fun provideRetrofitCommon(gson: Gson?): Retrofit {
val client = OkHttpClient.Builder()
.connectTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.build()
return Retrofit.Builder()
.client(client)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson!!))
.addConverterFactory(ScalarsConverterFactory.create())
.baseUrl(API_LOGIN_URL)
.build()
}
}