fix: Allow for injectable ObjectMapper to resolve serialization issues for Java 8 date type
This commit is contained in:
@ -1,5 +1,12 @@
|
|||||||
# Changelog
|
# 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
|
## [1.9.1] - October 17th, 2021
|
||||||
|
|
||||||
### Changed
|
### 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
|
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.
|
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
|
### 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)
|
> ⚠️ 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
|
# Kompendium
|
||||||
project.version=1.9.1
|
project.version=1.9.2
|
||||||
# Kotlin
|
# Kotlin
|
||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
# Gradle
|
# Gradle
|
||||||
|
@ -13,14 +13,19 @@ import io.ktor.routing.route
|
|||||||
/**
|
/**
|
||||||
* Provides an out-of-the-box route to return the generated [OpenApiSpec]
|
* Provides an out-of-the-box route to return the generated [OpenApiSpec]
|
||||||
* @param oas spec that is returned
|
* @param oas spec that is returned
|
||||||
|
* @param om provider for Jackson
|
||||||
*/
|
*/
|
||||||
fun Routing.openApi(oas: OpenApiSpec) {
|
fun Routing.openApi(
|
||||||
val om = ObjectMapper()
|
oas: OpenApiSpec,
|
||||||
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
|
om: ObjectMapper = objectMapper
|
||||||
.enable(SerializationFeature.INDENT_OUTPUT)
|
) {
|
||||||
route("/openapi.json") {
|
route("/openapi.json") {
|
||||||
get {
|
get {
|
||||||
call.respondText { om.writeValueAsString(oas) }
|
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.KompendiumParam
|
||||||
import io.bkbn.kompendium.annotations.ParamType
|
import io.bkbn.kompendium.annotations.ParamType
|
||||||
import io.bkbn.kompendium.annotations.UndeclaredField
|
import io.bkbn.kompendium.annotations.UndeclaredField
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
|
|
||||||
data class ExampleParams(
|
data class ExampleParams(
|
||||||
@ -27,6 +28,7 @@ data class ExampleRequest(
|
|||||||
val aaa: List<Long>
|
val aaa: List<Long>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class ExampleResponse(val c: String)
|
data class ExampleResponse(val c: String)
|
||||||
|
|
||||||
data class ExceptionResponse(val message: String)
|
data class ExceptionResponse(val message: String)
|
||||||
|
Reference in New Issue
Block a user