[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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 0 deletions

View File

@ -53,3 +53,20 @@ 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 {
{{#toJson}}
/*
.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.
*/
{{#jackson}}
return Serializer.jacksonObjectMapper.writeValueAsString(value).replace("\"", "")
{{/jackson}}
{{/toJson}}
{{^toJson}}
return value.toString()
{{/toJson}}
}

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("\"", "")
}

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("\"", "")
}