VKCOM / vk-android-sdk

Android library for working with VK API, authorization through VK app, using VK functions.
MIT License
456 stars 226 forks source link

com.google.gson.JsonSyntaxException при попытке выполнить запрос FriendsService().friendsGet() #543

Open tabatsky opened 1 year ago

tabatsky commented 1 year ago

При попытке получить список друзей получаю следующую ошибку:

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was NUMBER at path $.response.items[0]

Вариант исправления - заменить функцию из SDK на следующий код:

data class FriendsGetFieldsResponse(
    @SerializedName("count")
    val count: Int,
    @SerializedName("items")
    val items: List<Long>
)

fun friendsGet(
    userId: UserId? = null,
    order: FriendsGetOrderDto? = null,
    listId: Int? = null,
    count: Int? = null,
    offset: Int? = null,
    fields: List<UsersFieldsDto>? = null,
    ref: String? = null
): VKRequest<FriendsGetFieldsResponse> = NewApiRequest("friends.get") {
    GsonHolder.gson.parse<FriendsGetFieldsResponse>(it)
}
    .apply {
        userId?.let { addParam("user_id", it, min = 1) }
        order?.let { addParam("order", it.value) }
        listId?.let { addParam("list_id", it, min = 0) }
        count?.let { addParam("count", it, min = 0) }
        offset?.let { addParam("offset", it, min = 0) }
        val fieldsJsonConverted = fields?.map {
            it.value
        }
        fieldsJsonConverted?.let { addParam("fields", it) }
        ref?.let { addParam("ref", it, maxLength = 255) }
    } 

........

VK.execute(friendsGet(), object : VKApiCallback<FriendsGetFieldsResponse> {
    .........
}