From 2430796590f9fe4dd27c76ed2da87b8428f80380 Mon Sep 17 00:00:00 2001 From: xb205 <62425964+devxb@users.noreply.github.com> Date: Mon, 1 Apr 2024 14:18:56 +0900 Subject: [PATCH] feat: Support super type token in SagaEvent (#126) --- src/main/kotlin/org/rooftop/netx/api/SagaEvent.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/org/rooftop/netx/api/SagaEvent.kt b/src/main/kotlin/org/rooftop/netx/api/SagaEvent.kt index 02012d9..988c3ab 100644 --- a/src/main/kotlin/org/rooftop/netx/api/SagaEvent.kt +++ b/src/main/kotlin/org/rooftop/netx/api/SagaEvent.kt @@ -16,6 +16,12 @@ sealed class SagaEvent( return event } + fun <T : Any> decodeEvent(typeReference: TypeReference<T>): T = + codec.decode( + event ?: throw NullPointerException("Cannot decode event cause event is null"), + typeReference + ) + fun <T : Any> decodeEvent(type: Class<T>): T = decodeEvent(type.kotlin) fun <T : Any> decodeEvent(type: KClass<T>): T =