You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Provides serialization and deserialization support for nullable instances of TrackingToken.
55
+
*
56
+
* @see TrackingToken
57
+
*/
58
+
val trackingTokenSerializer =PolymorphicSerializer(TrackingToken::class).nullable
53
59
60
+
/**
61
+
* Serializer for the [ReplayToken.context], represented as a nullable String.
62
+
* This context is typically used to provide additional information during token replay operations.
63
+
*
64
+
* This serializer is used by [trackingTokenSerializer] to serialize the context field and now only [String] type or null value is supported!
65
+
* Sadly enough, there's no straightforward solution to support [Any]; not without adjusting the context field of the ReplayToken in Axon Framework itself.
66
+
* That is, however, a breaking change, and as such, cannot be done till version 5.0.0 of the Axon Framework.
67
+
* This also allow more complex objects as the context, although it requires the user to do the de-/serialization to/from String, instead of the Axon Framework itself.
68
+
* Look at AxonSerializersTest, case `replay token with complex object as String context` for an example how to handle that using Kotlin Serialization.
69
+
*
70
+
* @see ReplayToken.context
71
+
*/
72
+
val replayTokenContextSerializer =String.serializer().nullable
73
+
74
+
/**
75
+
* Module defining serializers for Axon Framework's core event handling and messaging components.
76
+
* This module includes serializers for TrackingTokens, ScheduleTokens, and ResponseTypes, enabling
77
+
* seamless integration with Axon-based applications.
@@ -76,21 +83,49 @@ internal class AxonSerializersTest {
76
83
}
77
84
78
85
@Test
79
-
funreplayToken() {
80
-
val token =ReplayToken.createReplayToken(GlobalSequenceTrackingToken(15), GlobalSequenceTrackingToken(10))
81
-
val json ="""{"tokenAtReset":{"type":"org.axonframework.eventhandling.GlobalSequenceTrackingToken","globalIndex":15},"currentToken":{"type":"org.axonframework.eventhandling.GlobalSequenceTrackingToken","globalIndex":10}}"""
val json ="""{"tokenAtReset":{"type":"org.axonframework.eventhandling.GlobalSequenceTrackingToken","globalIndex":15},"currentToken":{"type":"org.axonframework.eventhandling.GlobalSequenceTrackingToken","globalIndex":10},"context":"someContext"}""".trimIndent()
fun`replay token with currentToken with null value`() {
88
-
val token =ReplayToken.createReplayToken(GlobalSequenceTrackingToken(5), null)
89
-
val json ="""{"tokenAtReset":{"type":"org.axonframework.eventhandling.GlobalSequenceTrackingToken","globalIndex":5},"currentToken":null}"""
96
+
fun`replay token with currentToken with null value and null context`() {
97
+
val token =ReplayToken.createReplayToken(GlobalSequenceTrackingToken(5), null, null)
98
+
val json ="""{"tokenAtReset":{"type":"org.axonframework.eventhandling.GlobalSequenceTrackingToken","globalIndex":5},"currentToken":null,"context":null}"""
fun`replay token with complex object as String context`() {
112
+
@Serializable
113
+
data classComplexContext(valvalue1:String, valvalue2:Int, valvalue3:Boolean)
114
+
val complexContext =ComplexContext("value1", 2, false)
115
+
116
+
val token =ReplayToken.createReplayToken(
117
+
GlobalSequenceTrackingToken(15),
118
+
GlobalSequenceTrackingToken(10),
119
+
Json.encodeToString(complexContext)
120
+
)
121
+
val json ="""{"tokenAtReset":{"type":"org.axonframework.eventhandling.GlobalSequenceTrackingToken","globalIndex":15},"currentToken":{"type":"org.axonframework.eventhandling.GlobalSequenceTrackingToken","globalIndex":10},"context":"{\"value1\":\"value1\",\"value2\":2,\"value3\":false}"}""".trimIndent()
0 commit comments