fix: Allow for injectable ObjectMapper to resolve serialization issues for Java 8 date type

This commit is contained in:
Adrián Garcia
2021-10-24 18:25:55 +02:00
committed by GitHub
parent c8d56e62a2
commit d9d0f129b5
5 changed files with 42 additions and 5 deletions

View File

@ -13,14 +13,19 @@ import io.ktor.routing.route
/**
* Provides an out-of-the-box route to return the generated [OpenApiSpec]
* @param oas spec that is returned
* @param om provider for Jackson
*/
fun Routing.openApi(oas: OpenApiSpec) {
val om = ObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.enable(SerializationFeature.INDENT_OUTPUT)
fun Routing.openApi(
oas: OpenApiSpec,
om: ObjectMapper = objectMapper
) {
route("/openapi.json") {
get {
call.respondText { om.writeValueAsString(oas) }
}
}
}
private val objectMapper = ObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.enable(SerializationFeature.INDENT_OUTPUT)