https://kotlinlang.org logo
j

jw

06/30/2022, 2:15 PM
i have a public interface with properties in module A, a private data class implementing the interface in module B, and in module C (the only one I control) i need to create a serializer for the interface type (for encoding only). Are my only options a manually-written serializer for the interface or a surrogate? i really would like to avoid having to maintain a hand-written serializer but also would like the serialize without extra allocation of surrogates for every instance in the outgoing tree. My dream would be external seriazation generation through
@Serializer(forClass=)
but for an interface where the generated decoder throws UOE, or I could manually override decode and throw UOE
d

Dominaezzz

06/30/2022, 9:00 PM
At the moment those are your only options yes.
@Serializer(forClass=)
doesn't even work for public sealed classes yet. It's got a long way to go.
j

jw

06/30/2022, 9:05 PM
I went with surrogate for now. It's all codegen so it doesn't really matter, but allocation just to turn around and unpack it hurts me to see. But it's 3 LOC vs lots of code and lots of logic. Oh well.
d

Dominaezzz

06/30/2022, 9:19 PM
Well, if you have no concurrency you could cache the surrogate but I reckon that'll hurt to see as well.
3 Views