Hi, quick question, I have and endpoint that has a...
# serialization
a
Hi, quick question, I have and endpoint that has a dynamic property, it could be a
String
, an
Integer
or a
Boolean
, is there a way to achieve that behaviour with serialization?
tried having the property as a polymorphic Any and adding the types to the serialization module but it failed
Copy code
@Polymorphic val value: Any
Copy code
SerializersModule {
    polymorphic(Any::class) {
        subclass(String::class, String.serializer())
        subclass(Int::class, Int.serializer())
        subclass(Boolean::class, Boolean.serializer())
    }
}
p
Try if using a JsonPrimitive works
🙏 1
a
will try
p
If it doesn't then a JsonElement probably will
n
For cases like this I've tended to write my own sealed interface composed of inline classes. I dislike the ergonomics of the built-in JsonPrimitive class, and writing a sealed interface with the types that I need is pretty painless.
🙏 1