KAnnotatedElement represents a runtime declaration that can carry annotations. Interfaces such as KClass, KFunction, KParameter, and KProperty extend it, so reflection code can inspect annotations through a common API. section 12.2.1
Filtering annotated properties
A serializer can inspect each reflected property and exclude those marked with @JsonExclude: val properties = kClass.memberProperties .filter { it.findAnnotation<JsonExclude>() == null } Here, property.annotations exposes all runtime-retained annotations, while findAnnotation<JsonExclude>() returns the matching annotation or null. The same lookup supports annotations carrying values, such as @JsonName("alias"). section 12.2.3
Reflection-based serializers use KAnnotatedElement to:
- Read all annotations from a KProperty through its annotations collection. section 12.2.3
- Find one annotation by type with findAnnotation, then branch on its presence or read its arguments. section 12.2.3
