package com.margelo.nitro.fawrypay.rnfawrypaysdk import com.fawry.fawrypay.domain.models.BillItems import com.google.gson.* import java.lang.reflect.Type class InterfaceAdapter : JsonDeserializer, JsonSerializer { companion object { const val CLASSNAME = "CLASSNAME" const val DATA = "DATA" } @Throws(JsonParseException::class) override fun deserialize( jsonElement: JsonElement, type: Type, jsonDeserializationContext: JsonDeserializationContext ): BillItems? { val jsonObject = jsonElement.asJsonObject var payableItem: BillItems? = null try { val gson = Gson() payableItem = gson.fromJson(jsonObject, BillItems::class.java) } catch (e: Exception) { print("Error deserializing item $jsonObject") } return payableItem } override fun serialize( jsonElement: Any, type: Type, jsonSerializationContext: JsonSerializationContext ): JsonElement { val jsonObject = JsonObject() jsonObject.addProperty(CLASSNAME, jsonElement.javaClass.name) jsonObject.add(DATA, jsonSerializationContext.serialize(jsonElement)) return jsonObject } }