I’m getting the standard “Class ‘TaxSummary’ is no...
# serialization
s
I’m getting the standard “Class ‘TaxSummary’ is not registered for polymorphic serialization in the scope of ‘LineResponseTaxesInner’. Mark the base class as ‘sealed’ or register the serializer explicitly.” message, problem is, I have marked the serializer explicitly. I have
Copy code
@Serializable(with = TaxSerializer::class)
interface LineResponseTaxesInner {
and then my custom serializer
Copy code
object TaxSerializer : JsonContentPolymorphicSerializer<LineResponseTaxesInner>(LineResponseTaxesInner::class) {
    override fun selectDeserializer(element: JsonElement) = when {
        "FullDetails" in element.jsonObject -> Tax.serializer()
        else -> TaxSummary.serializer()
    }
}
Weirdly this works completely fine locally, but fails when compiled as a graalvm native image and run in aws…
a
> or register the serializer explicitly I suspect that doesn't mean adding
@Serializable
to the interface, but instead, registering it (and the subtypes) in the SerializersModule https://github.com/Kotlin/kotlinx.serialization/blob/v1.6.3/docs/polymorphism.md#registered-subclasses
KxS doesn't use reflection for encoding/decoding, but it does use reflection for fetching serializers. I've never used GraalVM, but I thought it didn't support reflection. I half-remember that the amount of support had changed in recent versions, but maybe reflection is only partially supported.
s
I also tried with registering that way but it did not work either. Neither way works. From my history of using graal and KxS together, that has always just entailed using
Blah.serializer()
rather than the extension functions. Hm..