The builder/DSL part may look something like this:
fun <T : Any> addType(builder: ClassConfig<T>.() -> Unit) {
val config = JacksonClassConfig<T>()
config.builder()
//get serializer from builder and add it to jackson
}
interface ClassConfig<T : Any> {
fun include(property: KProperty1<T, *>) = include(property, property.name)
fun include(property: KProperty1<T, *>, fieldName: String)
}
class JacksonClassConfig<T : Any> : ClassConfig<T> {
override fun include(property: KProperty1<T, *>, fieldName: String) {
println("including: $fieldName for property: $property")
//store the fields, build your own serializer
}
}
which you than would use like:
data class Person(val firstName: String, val lastName: String, val age: Int)
addType<Person> {
include(Person::firstName)
include(Person::lastName, "family-name")
}
How to build custom serialisers and deserialisers is described in the previous links.