melatonina
02/19/2021, 12:11 PMclass ProjectId(value: UUID) : Id(value) {
companion object {
fun new() = ProjectId(newValue())
}
}
where Id
is
@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.melatonina
02/19/2021, 2:58 PM