Hello. I have number of classes which represent UU...
# serialization
m
Hello. I have number of classes which represent UUIDs for different things, like the following:
Copy code
class ProjectId(value: UUID) : Id(value) {
    companion object {
        fun new() = ProjectId(newValue())
    }
}
where
Id
is
Copy code
@Serializable
abstract class Id(
    @Serializable(with = UUIDSerializer::class)
    val value: UUID
) {
    companion object {
        fun newValue(): UUID = UUID.randomUUID()
    }
    override fun hashCode(): Int = value.hashCode()
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other !is Id) return false

        if (!this.javaClass.isAssignableFrom(other.javaClass))
            return false

        return (value == other.value)
    }

    override fun toString(): String = "${javaClass.simpleName}($value)"
}
Is there a way to make all these
Id
subclasses serializable without writing the serializers by hand? Obviously, I'd like the various
Id
subclasses to be
inline
classes, but they would not be serializable at all.
I ended up generating all classes and their serializers with kapt.
👍🏻 1