Skip to content

Commit

Permalink
Fix query parameter serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
mrashed-dev committed Nov 8, 2023
1 parent 4151b69 commit c1e885b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/main/kotlin/com/nylas/NylasClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,21 @@ class NylasClient(

private fun addQueryParams(url: HttpUrl.Builder, params: Map<String, Any>): HttpUrl.Builder {
for ((key, value) in params) {
url.addQueryParameter(key, value.toString())
when (value) {
is List<*> -> {
for (item in value) {
url.addQueryParameter(key, item.toString())
}
}
is Map<*, *> -> {
for ((k, v) in value) {
url.addQueryParameter(key, "$k:$v")
}
}
else -> {
url.addQueryParameter(key, value.toString())
}
}
}
return url
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/nylas/models/IQueryParams.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface IQueryParams {
* Convert the query parameters to a json-formatted map.
* @return Map of query parameters
*/
fun convertToMap(): Map<String, String> {
fun convertToMap(): Map<String, Any> {
val json = JsonHelper.moshi()
.adapter(this.javaClass)
.toJson(this)
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/nylas/util/JsonHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ class JsonHelper {
* @suppress Not for public use.
*/
@JvmStatic
val jsonMapAdapter = moshi.adapter<Map<String, String>>(
mapTypeOf(String::class.java, String::class.java),
val jsonMapAdapter = moshi.adapter<Map<String, Any>>(
mapTypeOf(String::class.java, Any::class.java),
).indent(" ")

/**
Expand Down

0 comments on commit c1e885b

Please sign in to comment.