I found a solution where I am able to cast it in a bit more elegant way.
val map = if (value.all { it.key is String && it.value is Any }) {
value.cast<Map<String, Any>>()
} else {
throw IllegalArgumentException("Illegal argument exception for unsupported map type")
}
...
private inline fun <reified T> Any.cast(): T = this as T
and in similar way with the List<*>
.