File tree Expand file tree Collapse file tree
ktor-openapi/src/main/kotlin/io/github/smiley4/ktoropenapi Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package io.github.smiley4.ktoropenapi.config
22
3+ import com.fasterxml.jackson.databind.ObjectMapper
4+ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
35import io.github.smiley4.ktoropenapi.config.descriptors.KTypeDescriptor
46import io.github.smiley4.ktoropenapi.config.descriptors.TypeDescriptor
57import kotlinx.serialization.json.Json
@@ -21,9 +23,18 @@ object ExampleEncoder {
2123 example
2224 }
2325
26+ /* *
27+ * [GenericExampleEncoder] using a Jackson mapper to encode example objects.
28+ * @param json a jackson object mapper encoding objects to json. Set `null` to use a pre-configured object mapper.
29+ */
30+ fun jackson (json : ObjectMapper ? = null): GenericExampleEncoder = { type, example ->
31+ val mapper = json ? : jacksonObjectMapper()
32+ mapper.writeValueAsString(example)
33+ }
34+
2435 /* *
2536 * [GenericExampleEncoder] using kotlinx-serialization to encode example objects.
26- * @param json the kotlinx json serializer to use for encoding objects to json. Set `null` to use default kotlinx json serializer.
37+ * @param json a kotlinx json serializer to use for encoding objects to json. Set `null` to use default kotlinx json serializer.
2738 */
2839 fun kotlinx (json : Json ? = null): GenericExampleEncoder = { type, example ->
2940 when (type) {
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ internal class ExampleConfigData(
1414 val DEFAULT = ExampleConfigData (
1515 sharedExamples = emptyMap(),
1616 securityExamples = null ,
17- exampleEncoder = ExampleEncoder .internal ()
17+ exampleEncoder = ExampleEncoder .jackson ()
1818 )
1919 }
2020
You can’t perform that action at this time.
0 commit comments