Is it possible to type function arguments as `@ser...
# serialization
e
Is it possible to type function arguments as
@serializable
or having some annotation?
🚫 3
b
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
)
2
e
That makes sense, thanks.