I wonder what is the correct way to read, parse and serve a file from resources.
Currently, I do something like this:
fun getFile(request: ServerRequest): Mono<ServerResponse> {
val parsedJson =
objectMapper.readValue(readFile("fileName.json"), JsonModel::class.java)
// modify parsed json
return ok().contentType(APPLICATION_JSON).bodyValue(parsedJson)
}
private fun readFile(fileName: String) =
DefaultResourceLoader()
.getResource(fileName)
.inputStream.bufferedReader().use { it.readText() }
I've noticed JsonObjectDecoder class in Netty, but I don't know if can be applied to my use case.
What is the reactive way to do read/parse resource file then?
Mono#fromCallableand placed on its ownschedulerthats bounded to avoid thread starvation. You can read more about blocking calls here projectreactor.io/docs/core/release/reference/…