'cannot access JSON response body in KOTLIN
Im new to android development and now I'm having an issue when getting a response from the server. I tried different methods non of them are worked. Im using fuel and gson. This is my code.
// LoginResponse.kt
data class LoginResponse (
val x_access_token: String,
val user_id: String,
val public_id: String,
val email: String,
val status_code: Int
) {
class Deserializer : ResponseDeserializable<Array<LoginResponse>>{
override fun deserialize(content: String): Array<LoginResponse>
= Gson().fromJson(content,Array<LoginResponse>::class.java)
}
override fun toString(): String {
return "Response [x_access_token: ${this.x_access_token}, user_id: ${this.user_id}, public_id: ${this.public_id}, email: ${this.email}, status_code:${this.status_code}]"
}
}
this is the API response which im getting using postman
{
"x_access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwdWJsaWNfaWQiOiJkYjE3NzdiYS0wZTJhLTQxMzUtOGNjNC01ZWI5NjQ0OTk5ZDMiLCJleHAiOjE2NDQ0NzEzMjZ9.xkk6B6ntqcZzq1soNDEiUJSGRqS89ZfTZwgMxODBA64",
"user_id": "61d67f075492251b6129a6bc",
"public_id": "db1777ba-0e2a-4135-8cc4-5eb9644999d3",
"email": "[email protected]",
"status_code": 200
}
This is how I'm using fuel and gson
Fuel.post("https://api.bixchat.xyz/message/api/login")
.body(requestBodyJson.toString())
.header("content-type", "application/json")
.response { request, response, result ->
val gson = Gson()
val res: LoginResponse =
gson.fromJson(response.body().toString(), LoginResponse::class.java)
Log.e("dev", res.email)
}
and this is what I'm getting on the terminal
W/bixandroidthir: Accessing hidden field Lsun/misc/Unsafe;->theUnsafe:Lsun/misc/Unsafe; (greylist, reflection, allowed)
Accessing hidden method Lsun/misc/Unsafe;->allocateInstance(Ljava/lang/Class;)Ljava/lang/Object; (greylist, reflection, allowed)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
