I am experimenting with implementing "typed ids" s...
# serialization
r
I am experimenting with implementing "typed ids" similar to those used by Stripe. See article https://dev.to/stripe/designing-apis-for-humans-object-ids-3o5a. I've played around with various implementations but nothing comes out very clean and elegant on both the data model side and the kotlinx-serialization side. Anyone have any thoughts / design ideas? Ideally I'd like to have the serializable class be as simple as
data class FooBar(val id: TypedUuid<FooBar>, …)
and the serialization of
id
be as simple as
fb_<uuid>
.
The "obvious" implementation of
TypedId
takes the prefix as a parameter and has a custom serializer that reads/writes the correct format. But that requires the prefix to be passed at all constructor call sites, which sucks.
🙌 1
p
https://kotlinlang.slack.com/archives/C0B8MA7FA/p1735809739972849 this is a similar thread although not covering the KSerializer bit itself
👍 1
here's the example with KSerializer implemented (very basically) https://pl.kotl.in/qoA-nzqTp
r
That requires a separate
Id
type for each model type. Any thoughts on making that generic?