I want to add array type query parameter in kotlin...
# spring
u
I want to add array type query parameter in kotlin spring boot mvc project using MockMvc. To do this, i wrote code like this.
Copy code
val productIds: List<Long>

mockMvc.get("/someUrl") {
    param("productIds", productIds.joinToString(","))
}
But, i donโ€™t want to use joinToString and it looks ugly. Is there a nice any way to write code like this?
Copy code
mockMvc.get("/someUrl") {
    params("productIds", productIds)
}
r
assuming that
productIds
is an Array of Strings, I think it should work by using
*productIds
(spread operator, see docs), so like this:
Copy code
mockMvc.get("/someUrl") {
    param("productIds", *productIds)
}
๐Ÿ‘€ 1
u
productIds type is List<Long>. so do that, productIds.map { it.toString() }.toTypedArray() must be calledโ€ฆ
r
ah yeah, in that case
joinToString
is shorter ๐Ÿ˜…
u
too sad open eye crying laughing
k
however is it the same in the end?
looks like it is as spring accepts comma delimited values too
j
I recommend using joinToString if you want to test comma separated parameters. Use params multiple times if you want to test ?productIds=42&productIds=49. Both are valid forms of putting a list in query params, and you should be explicit about which form you're testing