diff --git a/parsely/src/main/java/com/parsely/parselyandroid/JsonSerializer.kt b/parsely/src/main/java/com/parsely/parselyandroid/JsonSerializer.kt index 95d6b314..dde232ce 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/JsonSerializer.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/JsonSerializer.kt @@ -5,13 +5,19 @@ import java.io.IOException import java.io.StringWriter internal object JsonSerializer { + + fun toParselyEventsPayload(eventsToSend: List?>): String { + val batchMap: MutableMap = HashMap() + batchMap["events"] = eventsToSend + return toJson(batchMap).orEmpty() + } /** * Encode an event Map as JSON. * * @param map The Map object to encode as JSON. * @return The JSON-encoded value of `map`. */ - fun toJson(map: Map): String? { + private fun toJson(map: Map): String? { val mapper = ObjectMapper() var ret: String? = null try { diff --git a/parsely/src/main/java/com/parsely/parselyandroid/SendEvents.kt b/parsely/src/main/java/com/parsely/parselyandroid/SendEvents.kt index bb3deaa2..1b1f4c96 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/SendEvents.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/SendEvents.kt @@ -1,6 +1,6 @@ package com.parsely.parselyandroid -import com.parsely.parselyandroid.JsonSerializer.toJson +import com.parsely.parselyandroid.JsonSerializer.toParselyEventsPayload import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch @@ -20,9 +20,7 @@ internal class SendEvents( } ParselyTracker.PLog("Sending request with %d events", eventsToSend.size) - val batchMap: MutableMap = HashMap() - batchMap["events"] = eventsToSend - val jsonPayload = toJson(batchMap).orEmpty() + val jsonPayload = toParselyEventsPayload(eventsToSend) ParselyTracker.PLog("POST Data %s", jsonPayload)