ktoml
ktoml copied to clipboard
A good idea is to use annotation processing with reflekt for the configuration
https://github.com/JetBrains-Research/reflekt
I think @SerialInfo from kotlinx.serialization could make it, like this:
@SerialInfo
@Target(AnnotationTarget.PROPERTY)
public annotation class Comment(vararg val texts: String)
// Model class
data class Account(
val username: String,
@Comment("Don't tell others!")
val password: String
)
// In Encoder
fun comment(descriptor: SerialDescriptor, index: Int) {
descriptor.getElementAnnotations(index)
.filterIsInstance<Comment>()
.map {
if (it.isEmpty())
emptyArray<String>()
else
it[0].texts // As Comment is not @Repeatable, we take the first
}
.forEach(writer::emitComment) // functional YES!
}
Yes, I think this is covered by kotlinx.serialization already. I'm not sure what functionality Reflekt would provide that we don't have access to, but I could be missing something
Yeah, it looks so. I actually wanted to add some custom annotations for compile time reflection, but yes Kotlinx.serialization already has mostly everything we need. May be we will use reflekt for something else next time :)