https://kotlinlang.org logo
#serialization
Title
# serialization
c

Colton Idle

09/30/2023, 9:26 PM
Is it possible to have a typealias that's serializable? I thought this would work, but no go
Copy code
@Serializable
typealias BOOP = String
the docs seem to say that String is a primitive that's supported but I can't seem to even get String.serializer() either
e

ephemient

09/30/2023, 11:20 PM
Copy code
typealias BOOP = @Serializable String
c

Colton Idle

09/30/2023, 11:38 PM
intesting. i could've sworn i tried that and it did't compile. but it did this time. i thought it would send it wrapped in json, but it just sends a raw string literal over the wire. So looks like I'll just do
Copy code
@Serializable
data class Thing(val boop: BOOP)

typealias BOOP = String
thanks @ephemient
e

ephemient

10/01/2023, 12:17 AM
if it's literally
String
there's no need anyway
1
it's more useful when you have
typealias SerializableFoo = @Serializable(with = ExternalFooSerializer::class) Foo
or other more meaningful annotations
👍 1
b

Ben Woodworth

10/01/2023, 3:01 AM