{ "iserror": false, "message": "Data retur...
# ktor
p
{ "iserror": false, "message": "Data returned successfully", "data": [ { "engineer_status": "Not Available", "plant_department_code": "1-1", "plant_department_name": "IOL", "skill_set": "", "tickets": "13", "scheduled": "13", "engineer_image": "

https://cmms.auswegprime.com/attachments/employee/placeholder.jpg

", "employee_id": "3", "company_id": "1", "employee_code": "2746", "employee_name": "SHANMUGAM K", "employee_gender": "", "employee_department": "undefined", "employee_active": "yes", "employee_type": "Engineer", "employee_image": "placeholder.jpg", "employee_mobile_no": "8489438849", "employee_address": "", "employee_email": "iolem@aurolab.com", "employee_skill_set": "", "status": "active", "is_login": "yes", "is_assigned": "yes", "plant_id": "1", "bu_id": "1", "department_id": "1", "password_login": "202cb962ac59075b964b07152d234b70", "pin_login": "81dc9bdb52d04dc20036dbd8313ed055", "lastlogin": "2023-06-12 183426", "custome_color": "skin-red", "custome_menu": "", "created_on": "2023-02-08 104523", "created_by": "1", "modified_on": "2023-04-08 125133", "modified_by": "1" } ] } this is my Json input
t
Which library do you use for Json serialization/deserialization? Also, is this error from the client or the server side. This is most probably a de-sync between the server and the client side definition.
p
Copy code
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
am using this library for serialization
are u saying it's a backend issue?
a
Can you share the code where the HTTP request is being made?
p
Copy code
class GetProductsUseCase: BaseUseCase<String, ArrayList<Engine>>() {
    override suspend fun execute(plant_id: String): ArrayList<Engine> {
        val response = <http://networkClient.post|networkClient.post>("<https://cmms.auswegprime.com/Api/get_plant_engineer_status_list>")
        return response.body()
    }
}
here
a
The problem is that you're trying to receive an
ArrayList
but the JSON's root element is an object.
So either the JSON's root element must be an array or you have to change what is being received.
p
Copy code
class GetProductsUseCase: BaseUseCase<String, List<Engine>>() {
    override suspend fun execute(plant_id: String): List<Engine> {
        val response = <http://networkClient.post|networkClient.post>("<https://cmms.auswegprime.com/Api/get_plant_engineer_status_list>")
        return response.body()
    }
}
now, its right?
a
You can check whether it's right or wrong by running the application. It seems like it's still wrong. Please read the documentation or some tutorials on the
kotlinx.serialization
framework to get a better understanding of how the mapping works.
p
@Aleksei Tirman [JB] okay, are you doing any freelancing for KMM?
🚫 1
a
@Praveen Kumar you'll need to wrap your
List<Engine>
within a data class with a property named
data
Example:
data class ApiResponse<T>(
val iserror: Boolean,
val message: String,
val data: T,
)
Copy code
class GetProductsUseCase: BaseUseCase<String, List<Engine>>() {
    override suspend fun execute(plant_id: String): List<Engine> {
        val response = <http://networkClient.post|networkClient.post>("<https://cmms.auswegprime.com/Api/get_plant_engineer_status_list>")
        return response.body<ApiResponse<List<Engine>>>().data
    }
}