@@ -59,7 +59,7 @@ internal inline fun <reified T> String.toList(serializer: KSerializer<List<T>>,
59
59
}
60
60
}
61
61
62
- internal inline fun <reified T : Any > String.toPagingObject (
62
+ internal fun <T : Any > String.toPagingObject (
63
63
tClazz : KClass <T >,
64
64
tSerializer : KSerializer <T >,
65
65
innerObjectName : String? = null,
@@ -68,24 +68,18 @@ internal inline fun <reified T : Any> String.toPagingObject(
68
68
arbitraryInnerNameAllowed : Boolean = false,
69
69
skipInnerNameFirstIfPossible : Boolean = true
70
70
): NullablePagingObject <T > {
71
- println (" here2" )
72
71
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 )
84
80
}
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 {
89
83
this .endpoint = endpoint
90
84
this .itemClazz = tClazz
91
85
this .items.map { obj ->
@@ -94,7 +88,6 @@ internal inline fun <reified T : Any> String.toPagingObject(
94
88
}
95
89
}
96
90
}
97
- println (" here5" )
98
91
99
92
return try {
100
93
val pagingObject = this .parseJson { json.decodeFromString(NullablePagingObject .serializer(tSerializer), this ) }
@@ -227,8 +220,10 @@ internal fun <T> String.parseJson(producer: String.() -> T): T =
227
220
try {
228
221
producer(this )
229
222
} catch (e: Exception ) {
223
+ println (e.message)
224
+ println (e.cause)
230
225
throw SpotifyException .ParseException (
231
- " Unable to parse $this " ,
226
+ " Unable to parse $this ( ${e.message} ) " ,
232
227
e
233
228
)
234
229
}
0 commit comments