Skip to content

Instantly share code, notes, and snippets.

@thomasmartin-whoz
Last active June 28, 2023 20:11
Show Gist options
  • Save thomasmartin-whoz/cb1835e343189f15751892dfaae31b13 to your computer and use it in GitHub Desktop.
Save thomasmartin-whoz/cb1835e343189f15751892dfaae31b13 to your computer and use it in GitHub Desktop.
override fun transformRequestObjectNodeReactive(
requestBody: ObjectNode
): Mono<ObjectNode> {
return if (requestBody.get("periods").isArray) {
val periods = (requestBody.get("periods") as ArrayNode).elements().asSequence().joinToString(",")
webClient
.get()
.uri("http://localhost/periods?code=${periods}")
.retrieve()
.bodyToMono<ArrayNode>()
.map { periodsBody ->
val periodIds:List<JsonNode> = periodsBody.elements().asSequence().map {it["id"]}.toList()
requestBody.set<ArrayNode>("periods", objectMapper.createArrayNode().addAll(periodIds))
requestBody
}
} else Mono.just(requestBody)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment