Take a look at how the polymorphic adapter is impl...
# squarelibraries
j
Take a look at how the polymorphic adapter is implemented in the repo
d
Ok so like this:
Copy code
override fun fromJson(reader: JsonReader): PaymentResult? {
		val peeked = reader.peekJson()

		return when(peeked.readId()) {
			200 -> jsonAdapter.fromJson(reader)!!
			403 -> PaymentResult.PaymentSuccededWithRegistrationNotCompleted
			401 -> PaymentResult.CouponOrProductNotFound
			402 -> PaymentResult.PaymentNotAccepted(reader.readError())
			420 -> PaymentResult.SellerIdNotValid
			else -> error("Invalid response from Odoo")
		}
	}

	fun JsonReader.readId(): Int {
		beginObject()
		while (hasNext()) {
			if(nextName() == "id") return nextInt() else skipValue()
		}

		error("Response Id not found")
	}

	fun JsonReader.readError(): String {
		beginObject()
		while (hasNext()) {
			if(nextName() == "error") return nextString() else skipValue()
		}
		
		error("Response error message not found")
	}
?