Coverage Summary for Class: ProductListResponseAdapter (cloud.mindbox.mobile_sdk.models.operation.adapters)

Class Method, % Branch, % Line, % Instruction, %
ProductListResponseAdapter 100% (3/3) 50% (1/2) 100% (5/5) 95% (38/40)
ProductListResponseAdapter$gson$2 100% (1/1) 100% (1/1) 100% (3/3)
ProductListResponseAdapter$read$1$1 100% (1/1) 80% (4/5) 88.9% (8/9) 89.5% (34/38)
ProductListResponseAdapter$read$1$1$1 100% (1/1) 100% (1/1) 100% (2/2)
ProductListResponseAdapter$read$1$1$WhenMappings
ProductListResponseAdapter$write$1 100% (1/1) 66.7% (4/6) 100% (3/3) 80.8% (21/26)
Total 100% (7/7) 69.2% (9/13) 94.7% (18/19) 89.9% (98/109)


 package cloud.mindbox.mobile_sdk.models.operation.adapters
 
 import cloud.mindbox.mobile_sdk.models.operation.response.CatalogProductListResponse
 import cloud.mindbox.mobile_sdk.models.operation.response.ProductListItemResponse
 import cloud.mindbox.mobile_sdk.utils.LoggingExceptionHandler
 import com.google.gson.Gson
 import com.google.gson.TypeAdapter
 import com.google.gson.reflect.TypeToken
 import com.google.gson.stream.JsonReader
 import com.google.gson.stream.JsonToken
 import com.google.gson.stream.JsonWriter
 
 internal class ProductListResponseAdapter : TypeAdapter<Any>() {
 
     private val gson by lazy { Gson() }
 
     override fun write(out: JsonWriter?, value: Any?) {
         LoggingExceptionHandler.runCatching {
             if (value == null) {
                 out?.nullValue()
             } else {
                 out?.jsonValue(gson.toJson(value))
             }
         }
     }
 
     override fun read(`in`: JsonReader?): Any? = `in`?.let { reader ->
         LoggingExceptionHandler.runCatching(defaultValue = null) {
             when (reader.peek()) {
                 JsonToken.NULL -> {
                     reader.nextNull()
                     return@runCatching null
                 }
                 JsonToken.BEGIN_ARRAY -> {
                     gson.fromJson<List<ProductListItemResponse>?>(
                         reader,
                         object : TypeToken<List<ProductListItemResponse>?>() {}.type
                     )
                 }
                 JsonToken.BEGIN_OBJECT -> {
                     gson.fromJson<CatalogProductListResponse?>(
                         reader,
                         CatalogProductListResponse::class.java
                     )
                 }
                 else -> null
             }
         }
     }
 }