Skip to content

Commit 858b597

Browse files
committed
solve deserializing objects w nested generic collection
Signed-off-by: Adam Ratzman <adam@adamratzman.com>
1 parent c297660 commit 858b597

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ dependencies {
4747
}
4848

4949
testImplementation('org.junit.jupiter:junit-jupiter-api:5.2.0')
50-
implementation(group: 'org.json', name: 'json', version: '20180130')
50+
testImplementation(group: 'org.json', name: 'json', version: '20180130')
5151
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
5252

5353
}

src/main/kotlin/com/adamratzman/spotify/utils/Helpers.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ package com.adamratzman.spotify.utils
55
import com.adamratzman.spotify.main.SpotifyAPI
66
import com.adamratzman.spotify.main.SpotifyException
77
import com.beust.klaxon.Json
8+
import com.beust.klaxon.JsonBase
89
import com.beust.klaxon.Klaxon
9-
import org.json.JSONObject
1010
import java.io.InvalidObjectException
1111
import java.net.URLEncoder
1212
import java.util.Base64
@@ -96,7 +96,7 @@ internal inline fun <reified T> String.toPagingObject(
9696

9797
return PagingObject(
9898
jsonObject.string("href")!!,
99-
JSONObject(jsonObject.toJsonString()).getJSONArray("items").toString().toArray<T>(endpoint.api),
99+
(jsonObject["items"] as JsonBase).toJsonString().toArray<T>(endpoint.api),
100100
jsonObject.int("limit")!!,
101101
jsonObject.string("next"),
102102
jsonObject.int("offset")!!,
@@ -117,7 +117,7 @@ internal inline fun <reified T> String.toCursorBasedPagingObject(
117117

118118
return CursorBasedPagingObject(
119119
jsonObject.string("href")!!,
120-
JSONObject(jsonObject.toJsonString()).getJSONArray("items").toString().toArray<T>(endpoint.api),
120+
(jsonObject["items"] as JsonBase).toJsonString().toArray<T>(endpoint.api),
121121
jsonObject.int("limit")!!,
122122
jsonObject.string("next"),
123123
endpoint.api.klaxon.parseFromJsonObject(jsonObject.obj("cursors")!!)!!,
@@ -132,7 +132,7 @@ internal inline fun <reified T> String.toLinkedResult(api: SpotifyAPI): LinkedRe
132132
val jsonObject = api.klaxon.parseJsonObject(this.reader())
133133
return LinkedResult(
134134
jsonObject.string("href")!!,
135-
JSONObject(jsonObject.toJsonString()).getJSONArray("items").toString().toArray<T>(api)
135+
(jsonObject["items"] as JsonBase).toJsonString().toArray(api)
136136
)
137137
}
138138

0 commit comments

Comments
 (0)