Moshi
Add this optional artifact alongside a recorder to use map-based States. Use the same version as your recorder. See States for registration and snapshot requirements.
CorynStateMap
class CorynStateMap(map: Map<String, Any?>) : Map<String, Any?>, CorynState {
constructor()
constructor(first: Pair<String, Any?>, vararg pairs: Pair<String, Any?>)
fun copy(map: Map<String, Any?> = this): CorynStateMap
override fun equals(other: Any?): Boolean
override fun hashCode(): Int
override fun toJsonString(): String
companion object {
fun corynStateMapOf(vararg pairs: Pair<String, Any?>): CorynStateMap
}
}
The constructor, copy, and corynStateMapOf copy the outer map. They do not deep-copy nested values; nested objects and collections must remain stable. Equality and hashing compare map entries. toJsonString() uses the selected module's serializer on a worker thread. The factory is Java static; the other operations are available on the instance.
import ai.coryn.replay.api.core.main.Coryn
import ai.coryn.replay.api.stateserialization.moshi.model.CorynStateMap.Companion.corynStateMapOf
Coryn.addEvent("CheckoutCompleted", corynStateMapOf("itemCount" to 3))
The no-argument constructor creates an empty State. CorynStateMap implements the read-only Map interface. Serialisation uses reflection; prefer a dedicated CorynState with a generated serializer for large or frequently changing States.
CorynMapStateProvider
interface CorynMapStateProvider : CorynStateProvider<CorynStateMap>
Implement getState(): CorynStateMap? and optionally onProviderRemove(). Both callbacks run on the main thread. Register an instance with Coryn.provide or the manual provider API; see State Providers.
Inline factories
inline fun CorynMapStateProvider(
crossinline getState: () -> Map<String, Any>?
): CorynMapStateProvider
inline fun CorynMapStateProvider(
crossinline getState: () -> Map<String, Any>?,
crossinline onProviderRemove: () -> Unit
): CorynMapStateProvider
Call these factories after Coryn.init(). They wrap each non-null returned map in a Moshi CorynStateMap; callbacks run on the main thread when the provider is used. Register the result with Coryn.provide or the manual provider API.