I want to find memberProperties
that are not other classes I declared.
For example
data class X(val other: String)
data class Y(val str: String, val y: X?)
I want to filter()
my Y::class.memberProperties
such that only str
is included.
In other words, I want to only return built-in types, such as java.util.Date, String, Int, Long, BigDecimal, Decimal, Double...etc and their nullable counterparts.
What I tried (and that doesn't work):
Y::class.memberProperties.filter { it.returnType.javaClass.isPrimitive }
(returned 0 properties)
Update:
I managed to work around my issue for now like so:
Y::class.memberProperties.filter { !it.returnType.javaType.typeName.startsWith("com.myapp") }
However, this is plenty fragile as if I use any third party libs I might end up with types also included.
To make it clearer and give a more practical example, I am looking to exclude ALL types which, when serialized to JSON, do NOT serialize with properties beginning with {
.