Coverage Summary for Class: CustomFields (cloud.mindbox.mobile_sdk.models.operation)
| Class |
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| CustomFields |
60%
(3/5)
|
0%
(0/2)
|
66.7%
(4/6)
|
42.6%
(29/68)
|
| CustomFields$convertTo$1 |
100%
(1/1)
|
|
100%
(2/2)
|
100%
(13/13)
|
| Total |
66.7%
(4/6)
|
0%
(0/2)
|
75%
(6/8)
|
51.9%
(42/81)
|
package cloud.mindbox.mobile_sdk.models.operation
import cloud.mindbox.mobile_sdk.models.operation.adapters.CustomerFieldsAdapter
import cloud.mindbox.mobile_sdk.utils.LoggingExceptionHandler
import com.google.gson.Gson
import com.google.gson.annotations.JsonAdapter
import androidx.core.util.Pair as AndroidXPair
@JsonAdapter(CustomerFieldsAdapter::class)
public class CustomFields(public val fields: Map<String, Any?>? = null) {
/**
* Convert [CustomFields] value to [T] typed object.
*
* @param classOfT Class type for result [CustomFields] object.
*
* **Important:** [T] is a caller-supplied type deserialized via Gson. All constructor
* properties of [T] must declare [@SerializedName][com.google.gson.annotations.SerializedName]
* to ensure correct serialization after code shrinking (ProGuard/R8).
*/
public fun <T> convertTo(classOfT: Class<T>): T? = LoggingExceptionHandler.runCatching(defaultValue = null) {
val gson = Gson()
gson.fromJson(gson.toJson(fields), classOfT)
}
public constructor(vararg pairs: Pair<String, Any?>) : this(pairs.toMap())
public constructor(
vararg pairs: AndroidXPair<String, Any?>
) : this(*pairs.mapNotNull { pair -> pair.first?.let { Pair(it, pair.second) } }.toTypedArray())
override fun toString(): String = "CustomFields(fields=$fields)"
}