Matthew Cachia

02/26/2021, 7:27 AM
Hi, I'd like your opinion on using Klaxon deserialising one of two complex objects. As you can see from the image (OpenApi 3.1.0 specification), a json payload may return either a ResponseObject or a ReferenceObject. • I was thinking of expressing this using _arrow-kt_'s Either<ResponseObject, ReferenceObject> • I would also create a custom converter for this. My question is as follows: is it practical/recommended to the same
instance inside the converter? The job of the converter is to assemble the right Either construct, and therefore I'd like to delegate the deserialising of those two complex classes back into Klaxon.
Copy code
class EitherConverter(val klaxon: Klaxon): Converter {
    override fun canConvert(cls: Class<*>) = ???
    override fun fromJson(jv: JsonValue) = ???
    override fun toJson(o: Any) = ???
Is this the right approach? Are there better alternatives? Thank you everyone.