Do you want it for a compilation error? Instead of finding out later at runtime
If there were a way, I'd assume e.g.
Json.encodeToString(value)
would've use it. Technically though anything could be serializable depending on the Json instance's serializersModule, so it's a little fuzzy what actually counts as serializable, and is also out of reach from the type system because it's configurable.
In the past (especially for testing) I've used a simple SerializableValue class, passing around the value bundled with its serializer. It can be a bit obtrusive though depending on what you're doing.
Copy code
data class SerializableValue<T>(
val serializer: KSerializer<T>,
val value: T
)