fix: Allow for injectable ObjectMapper to resolve serialization issues for Java 8 date type
This commit is contained in:
@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## [1.9.2] - October 24th, 2021
|
||||
|
||||
### Changed
|
||||
|
||||
- Jackson ObjectMapper passed by parameter to openapi module
|
||||
- Added serializable annotation to ExceptionResponse
|
||||
|
||||
## [1.9.1] - October 17th, 2021
|
||||
|
||||
### Changed
|
||||
|
23
README.md
23
README.md
@ -126,6 +126,29 @@ suggestions on better implementations are welcome 🤠
|
||||
Under the hood, Kompendium uses Jackson to serialize the final api spec. However, this implementation detail
|
||||
does not leak to the actual API, meaning that users are free to choose the serialization library of their choice.
|
||||
|
||||
Added the possibility to add your own ObjectMapper for Jackson.
|
||||
|
||||
Added a default parameter with the following configuration:
|
||||
|
||||
```kotlin
|
||||
ObjectMapper()
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
|
||||
.enable(SerializationFeature.INDENT_OUTPUT)
|
||||
```
|
||||
|
||||
If you want to change this default configuration and use your own ObjectMapper you only need to pass it as a second argument to the openApi module:
|
||||
|
||||
```kotlin
|
||||
routing {
|
||||
openApi(oas, objectMapper)
|
||||
route("/potato/spud") {
|
||||
notarizedGet(simpleGetInfo) {
|
||||
call.respond(HttpStatusCode.OK)
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Route Handling
|
||||
|
||||
> ⚠️ Warning: Custom route handling is almost definitely an indication that either a new selector should be added to kompendium-core or that kompendium is in need of another module to handle a new ktor companion module. If you have encountered a route selector that is not already handled, please consider opening an [issue](https://github.com/bkbnio/kompendium/issues/new)
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Kompendium
|
||||
project.version=1.9.1
|
||||
project.version=1.9.2
|
||||
# Kotlin
|
||||
kotlin.code.style=official
|
||||
# Gradle
|
||||
|
@ -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)
|
||||
|
@ -4,6 +4,7 @@ import io.bkbn.kompendium.annotations.KompendiumField
|
||||
import io.bkbn.kompendium.annotations.KompendiumParam
|
||||
import io.bkbn.kompendium.annotations.ParamType
|
||||
import io.bkbn.kompendium.annotations.UndeclaredField
|
||||
import kotlinx.serialization.Serializable
|
||||
import org.joda.time.DateTime
|
||||
|
||||
data class ExampleParams(
|
||||
@ -27,6 +28,7 @@ data class ExampleRequest(
|
||||
val aaa: List<Long>
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ExampleResponse(val c: String)
|
||||
|
||||
data class ExceptionResponse(val message: String)
|
||||
|
Reference in New Issue
Block a user