Coverage Summary for Class: CustomerFieldsAdapter (cloud.mindbox.mobile_sdk.models.operation.adapters)
| Class |
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| CustomerFieldsAdapter |
100%
(3/3)
|
50%
(1/2)
|
100%
(5/5)
|
95.1%
(39/41)
|
| CustomerFieldsAdapter$gson$2 |
100%
(1/1)
|
|
100%
(1/1)
|
100%
(3/3)
|
| CustomerFieldsAdapter$read$1$1 |
100%
(1/1)
|
50%
(2/4)
|
50%
(2/4)
|
78.6%
(22/28)
|
| CustomerFieldsAdapter$write$1 |
100%
(1/1)
|
33.3%
(2/6)
|
66.7%
(2/3)
|
59.3%
(16/27)
|
| Total |
100%
(6/6)
|
41.7%
(5/12)
|
76.9%
(10/13)
|
80.8%
(80/99)
|
package cloud.mindbox.mobile_sdk.models.operation.adapters
import cloud.mindbox.mobile_sdk.models.operation.CustomFields
import cloud.mindbox.mobile_sdk.utils.LoggingExceptionHandler
import com.google.gson.Gson
import com.google.gson.TypeAdapter
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonToken
import com.google.gson.stream.JsonWriter
internal class CustomerFieldsAdapter : TypeAdapter<CustomFields?>() {
private val gson by lazy { Gson() }
override fun write(out: JsonWriter?, value: CustomFields?) {
LoggingExceptionHandler.runCatching {
if (value == null) {
out?.nullValue()
} else {
out?.jsonValue(gson.toJson(value.fields))
}
}
}
override fun read(`in`: JsonReader?): CustomFields? = `in`?.let { reader ->
LoggingExceptionHandler.runCatching(defaultValue = null) {
if (reader.peek() === JsonToken.NULL) {
reader.nextNull()
return@runCatching null
}
gson.fromJson<Map<String, Any?>?>(reader, Map::class.java)?.let(::CustomFields)
}
}
}