toObjectSecure

fun <T : Serializable> ByteArray.toObjectSecure(expectedClass: Class<T>, allowedClasses: Set<Class<*>> = emptySet()): T

Deserialize with type validation and security checks.

Parameters

expectedClass

The expected class type for validation

allowedClasses

Set of classes allowed for deserialization (security whitelist)

Throws

if the deserialized object is not in the allowed classes

if the object cannot be cast to the expected type