-
Notifications
You must be signed in to change notification settings - Fork 39
V2 Example Serialization
Lukas Ruegner edited this page Jun 2, 2024
·
2 revisions
json-serialization (for examples) is the conversion from any value (of a given type kotlin.reflect.KType
) to a json-string. This behavior can be customized, overwritten or completely replaced in the plugin-config encoding
-section.
This project uses jackson as the default json-serializer. The configuration of the object-mapper can be customized freely via the "EncodingData".
EncodingData.DEFAULT_EXAMPLE_OBJECT_MAPPER = jacksonObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
The default json-serializer can be completely replaced by another one in the plugin-config encoding
-section.
install(SwaggerUI) {
encoding {
exampleEncoder { type, value ->
// convert 'value' to json and return as string
}
}
}
-
exampleEncoder
- converts the given value (of the specified typetype
) to a valid json-string
It is also possible to only replace the serializer for specific types.
exampleEncoder { type, value ->
when (type) {
getSchemaType<String>() -> value.toString() // custom "serializer" for strings
else -> EncodingData.encodeExample(value) // use default serializer for everything else
}
}
An example replacing jackson with kotlinx can be found here.
- Getting Started
- Configuration
- Documenting Routes
- Multiple Api-Specs
- Examples
- Changelog
Documentation for previous versions: