@@ -59,7 +59,7 @@ internal inline fun <reified T> String.toList(serializer: KSerializer<List<T>>,
5959 }
6060}
6161
62- internal inline fun <reified T : Any > String.toPagingObject (
62+ internal fun <T : Any > String.toPagingObject (
6363 tClazz : KClass <T >,
6464 tSerializer : KSerializer <T >,
6565 innerObjectName : String? = null,
@@ -68,24 +68,18 @@ internal inline fun <reified T : Any> String.toPagingObject(
6868 arbitraryInnerNameAllowed : Boolean = false,
6969 skipInnerNameFirstIfPossible : Boolean = true
7070): NullablePagingObject <T > {
71- println (" here2" )
7271 if (innerObjectName != null || (arbitraryInnerNameAllowed && ! skipInnerNameFirstIfPossible)) {
73- println (" here3 $tClazz " )
74- val map = this .parseJson {
75- val t = (String .serializer() to NullablePagingObject .serializer(tSerializer)).apply { println (" serializer done" ) }
76- val jsonObjectRoot = (json.parseToJsonElement(this ) as JsonObject )
77- val jsonElement = innerObjectName?.let { jsonObjectRoot[it] } ? : jsonObjectRoot.keys.firstOrNull()?.let { jsonObjectRoot[it] }
78- ? : throw SpotifyException .ParseException (" Json element was null for class $tClazz (json $this )" )
79- val objectString = json.encodeToString(jsonElement)
80-
81- println (objectString)
82- println (json.decodeFromString<NullablePagingObject <T >>(objectString))
83- json.decodeFromString(MapSerializer (t.first, t.second), this ).apply { println (" decoded" ) }
72+ val jsonObjectRoot = (json.parseToJsonElement(this ) as JsonObject )
73+ val jsonElement = innerObjectName?.let { jsonObjectRoot[it] } ? : jsonObjectRoot.keys.firstOrNull()?.let { jsonObjectRoot[it] }
74+ ? : throw SpotifyException .ParseException (" Json element was null for class $tClazz (json $this )" )
75+ // println(jsonElement.toString())
76+ val objectString = jsonElement.toString()
77+
78+ val map = objectString.parseJson {
79+ json.decodeFromString(NullablePagingObject .serializer(tSerializer),this )
8480 }
85- println (" here4" )
86- return (map[innerObjectName] ? : if (arbitraryInnerNameAllowed) map.keys.firstOrNull()?.let { map[it] }
87- ? : error(" " ) else error(" " ))
88- .apply {
81+
82+ return map.apply {
8983 this .endpoint = endpoint
9084 this .itemClazz = tClazz
9185 this .items.map { obj ->
@@ -94,7 +88,6 @@ internal inline fun <reified T : Any> String.toPagingObject(
9488 }
9589 }
9690 }
97- println (" here5" )
9891
9992 return try {
10093 val pagingObject = this .parseJson { json.decodeFromString(NullablePagingObject .serializer(tSerializer), this ) }
@@ -227,8 +220,10 @@ internal fun <T> String.parseJson(producer: String.() -> T): T =
227220 try {
228221 producer(this )
229222 } catch (e: Exception ) {
223+ println (e.message)
224+ println (e.cause)
230225 throw SpotifyException .ParseException (
231- " Unable to parse $this " ,
226+ " Unable to parse $this ( ${e.message} ) " ,
232227 e
233228 )
234229 }
0 commit comments