[kotlin][spring-webclient] Add parseDateToQueryString (#16069)

This commit is contained in:
Jens Wetterich
2023-07-12 04:17:53 +02:00
committed by GitHub
parent 0a6671044f
commit 3325edc5c5
3 changed files with 37 additions and 0 deletions

View File

@@ -53,3 +53,13 @@ open class ApiClient(protected val client: WebClient) {
private fun <I : Any> WebClient.RequestBodySpec.body(requestConfig: RequestConfig<I>) =
apply { if (requestConfig.body != null) bodyValue(requestConfig.body) }
}
inline fun <reified T: Any> parseDateToQueryString(value : T): String {
/*
.replace("\"", "") converts the json object string to an actual string for the query parameter.
The moshi or gson adapter allows a more generic solution instead of trying to use a native
formatter. It also easily allows to provide a simple way to define a custom date format pattern
inside a gson/moshi adapter.
*/
return Serializer.jacksonObjectMapper.writeValueAsString(value).replace("\"", "")
}