-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Closed as not planned
Closed as not planned
Copy link
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issueA duplicate of another issue
Description
Description
I would like to request a feature that allows passing a POJO as query string in Spring’s HTTP Interface
Currently, while migrating from OpenFeign, I noticed that Spring does not provide an equivalent to Feign’s @QueryMap. Because of this limitation, I had to implement my own HttpServiceArgumentResolver to achieve the same behavior.
Reference from Feign documentation:
https://docs.spring.io/spring-cloud-openfeign/reference/spring-cloud-openfeign.html#feign-querymap-support
This request is very similar to #34227.
Could this functionality be added as a built-in feature in Spring? Alternatively, I can prepare a PR if that would help
Custom Implementation
@Target(AnnotationTarget.VALUE_PARAMETER)
@Retention(AnnotationRetention.RUNTIME)
annotation class QueryMap
class QueryMapHttpServiceArgumentResolver : HttpServiceArgumentResolver {
override fun resolve(argument: Any?, parameter: MethodParameter, requestValues: HttpRequestValues.Builder): Boolean {
if (!parameter.hasParameterAnnotation(QueryMap::class.java)) return false
requireNotNull(argument) { "argument cannot be null" }
for (entry in argument.toMap()) {
requestValues.addRequestParameter(entry.key, entry.value)
}
return true
}
private fun Any.toMap(): Map<String, String?> {
return (this::class as KClass<Any>).memberProperties.associate { prop ->
prop.name to prop.get(this)?.toString()
}
}
}
interface TestClient {
@GetExchange("/test")
fun queryObject(@QueryMap dto: TestDto): String
}
data class TestDto(
val id: Long,
val name: String,
)
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issueA duplicate of another issue