How can one easily build an url having queryParameters if I have the queryParams in a simple
val params= mapOf("foo" to "bar")
, how can I pass it to an
UriComponentBuilder
?
✅ 1
k
Klitos Kyriacou
06/15/2023, 11:26 AM
Copy code
val uri = UriComponentsBuilder.newInstance()
.scheme("http")
.host("<http://example.org|example.org>")
.path("example/path")
.query("fn={firstName}")
.query("sn={surname}")
.buildAndExpand(mapOf("firstName" to "John", "surname" to "Smith"))
.toUri()
p
Pihentagy
06/15/2023, 11:31 AM
Thanks. It seems that you have to map the map keys (eg
firstName
) to query parameters (
fn
). Isn't there a one-stop solution, so that if I have
Ah thanks, seems to be there is no one-stop solution for that. CollectionUtils could have some method for this purpose. Since that is implemented, I'll go for your second solution. Thanks