diff --git a/rudderreporter/src/main/java/com/rudderstack/android/ruddermetricsreporterandroid/LibraryMetadata.kt b/rudderreporter/src/main/java/com/rudderstack/android/ruddermetricsreporterandroid/LibraryMetadata.kt index b9e7b9bf2..42d10cc8f 100644 --- a/rudderreporter/src/main/java/com/rudderstack/android/ruddermetricsreporterandroid/LibraryMetadata.kt +++ b/rudderreporter/src/main/java/com/rudderstack/android/ruddermetricsreporterandroid/LibraryMetadata.kt @@ -20,6 +20,9 @@ import com.rudderstack.rudderjsonadapter.JsonAdapter import com.squareup.moshi.Json data class LibraryMetadata( + @get:JsonProperty("name") + @SerializedName("name") + @Json(name = "name") val name: String, @get:JsonProperty("sdk_version") @SerializedName("sdk_version") diff --git a/rudderreporter/src/main/java/com/rudderstack/android/ruddermetricsreporterandroid/metrics/MetricModel.kt b/rudderreporter/src/main/java/com/rudderstack/android/ruddermetricsreporterandroid/metrics/MetricModel.kt index aa5c02473..d880c4026 100644 --- a/rudderreporter/src/main/java/com/rudderstack/android/ruddermetricsreporterandroid/metrics/MetricModel.kt +++ b/rudderreporter/src/main/java/com/rudderstack/android/ruddermetricsreporterandroid/metrics/MetricModel.kt @@ -14,19 +14,40 @@ package com.rudderstack.android.ruddermetricsreporterandroid.metrics +import androidx.annotation.Keep import com.fasterxml.jackson.annotation.JsonIgnore import com.rudderstack.android.ruddermetricsreporterandroid.JSerialize import com.rudderstack.rudderjsonadapter.JsonAdapter import com.squareup.moshi.Json -open class MetricModel(val name: String, val type: MetricType, - val value: T, val labels: Map) : JSerialize> { +open class MetricModel( + val name: String, val type: MetricType, val value: T, val labels: Map +) : JSerialize> { + + companion object { + @Keep + private const val NAME_TAG = "name" + + @Keep + private const val TYPE_TAG = "type" + + @Keep + private const val VALUE_TAG = "value" + + @Keep + private const val LABELS_TAG = "labels" + } + override fun serialize(jsonAdapter: JsonAdapter): String? { - mapOf("name" to name, "type" to type, "value" to value, "labels" to labels).let { + toMap().let { return jsonAdapter.writeToJson(it) } } + protected open fun toMap(): Map { + return mapOf(NAME_TAG to name, TYPE_TAG to type, VALUE_TAG to value, LABELS_TAG to labels) + } + override fun equals(other: Any?): Boolean { if (this === other) return true if (other !is MetricModel<*>) return false @@ -48,21 +69,25 @@ open class MetricModel(val name: String, val type: MetricType, } override fun toString(): String { - return "MetricModel(name='$name', type=$type, value=$value, labels=$labels)" + return "MetricModel($NAME_TAG ='$name', $TYPE_TAG = $type, $VALUE_TAG = $value, $LABELS_TAG = $labels)" } } -class MetricModelWithId(@Transient - @JsonIgnore - @field:Json(ignore = true) - val id: String, name: String, type: MetricType, - value: T, labels: Map) : MetricModel(name, type, value, labels) { - override fun serialize(jsonAdapter: JsonAdapter): String? { - mapOf("id" to id, "name" to name, "type" to type, "value" to value, "labels" to labels).let { - return jsonAdapter.writeToJson(it) - } +class MetricModelWithId( + @Transient @JsonIgnore @field:Json(ignore = true) val id: String, + name: String, + type: MetricType, + value: T, + labels: Map +) : MetricModel(name, type, value, labels) { + companion object { + @Keep private const val ID_TAG = "id" + } + + override fun toMap(): Map { + return super.toMap() + mapOf(ID_TAG to id) } override fun equals(other: Any?): Boolean { @@ -74,7 +99,7 @@ class MetricModelWithId(@Transient } override fun toString(): String { - return "MetricModelWithId(id='$id'), parent = ${super.toString()})" + return "MetricModelWithId(i$ID_TAG='$id'), parent = ${super.toString()})" } } \ No newline at end of file