For a Spring Boot app we want to add some extra me...
# announcements
r
For a Spring Boot app we want to add some extra meta data to particular fields in the JSON response. Since this is a "cross cutting" concern in our project we want to make this as simple/concise as possible. We made a proof of concept with annotations. So we created 2 annotations and used reflection to generate the metadata based on the annotated fields. An example to use this is:
Copy code
data class Response(
    val id: Int,
    @MyFirstMetadata
    val label: LabelResponse
)
The idea that for the field
label
we generate some metadata and add this as extra fields in
LabelResponse
. I wonder if there's a way to reach our goal without annotations and reflection. I read about making DSL's in Kotlin, but I couldn't directly find something for our situation. I'm happy to hear your thoughts.
s
I think you can try using delegated properties here. The properties would look like normal properties for the clients, but they will have additional functionality attached to them. I am not sure if it fits well for your particular usages, but you might want to check JetBrains/Exposed to see what you can do with them on a real project.
👍 2
r
At a first glance it looks like it may fit my case, but I'm not sure. I will play around with it. Thnx Sasha
n
with annotations but without reflection you could use a compile-time annotation processor • otherwise, AOP is still possible
r
• Good point! That is our next step in our PoC, because we also want to add compile-time "validation". Didn't know we can drop reflection then as well. • Thx for that pointer, I will look a bit into AoP in Kotlin