```AppScope.launch { DataAccess.getRec...
# kvision
u
Copy code
AppScope.launch {
            DataAccess.getRecords().catch {
                Toast.error("Błąd pobierania danych z serwera")
            }.then { records ->
                println("Records: $records")
                val filtered = ArrayList<EntryRecord>()
                for(record in records.unsafeCast<List<EntryRecord>>()) {
                    if(!record.pricePrepaidConfirmed || !record.priceTotalConfirmed) {
                        filtered.add(record)
                    }
                }
records variable is of type kotlin.Unit apparently...
r
How is
getRecords()
defined?
u
Copy code
fun getRecords(): Promise<List<EntryRecord>> {
    return RestClient().call("/api/v1/records")
}
r
try this:
Copy code
fun getRecords(): Promise<List<EntryRecord>> {
    return RestClient().call("/api/v1/records") {
        deserializer = ListSerializer(EntryRecord.serializer())
    }
}
u
Still the same problem
r
Is this public API I could test?
u
No, it's a small project I'm working on, but the endpoint response is this: ``````
Copy code
[{"id":1,"creationDate":null,"contractType":"Test","contractNumber":"Test","pricePrepaid":20099,"pricePrepaidConfirmed":false,"priceTotal":400099,"priceTotalConfirmed":false,"additionalInformation":""}]
Also since it doesnt look like kvision has any specific piping for handling reponses from server-side APIs, I should probably move this question to javascript channel I think...
r
It seems to work for me but you have got a typo "additionaInformation" instead of "additionalInfo".
Also new
RestClient
from KVision 5 doesn't include serialization module for
Date
type. So you will need to provide a serializer if you want to use
Date
. E.g.:
Copy code
fun getRecords(): Promise<List<EntryRecord>> {
        return RestClient{
            serializersModule = serializersModuleOf(DateSerializer)
        }.call("/test.json") {
            deserializer = ListSerializer(EntryRecord.serializer())

        }
    }
And what do you mean by "specific piping for handling reponses from server-side APIs"?
u
And what do you mean by "specific piping for handling reponses from server-side APIs"?
A long time ago when I was trying to learn js I remember that a few frameworks had some helper methods to fetch data from the backend, I suspected that kvision might have something like this as well
It seems to work for me but you have got a typo "additionaInformation" instead of "additionalInfo".
Eh, where? Full project search for the phrase returns only additionalInformation in my project. Also I setill have the same problem...
Can't tell if I was using old sources or if it's what I think, but when I return the final list instead of a promise everything seems to work correctly