11package io .kurrent .dbclient .samples .appending_events ;
22
3+ import com .fasterxml .jackson .core .JsonProcessingException ;
34import io .kurrent .dbclient .*;
45import io .kurrent .dbclient .samples .TestEvent ;
56
67import java .util .UUID ;
78import java .util .concurrent .ExecutionException ;
89
10+ import com .fasterxml .jackson .databind .ObjectMapper ;
11+
12+
913public class AppendingEvents {
10- private static void appendToStream (KurrentDBClient client ) throws ExecutionException , InterruptedException {
14+ private static void appendToStream (KurrentDBClient client ) throws ExecutionException , InterruptedException , JsonProcessingException {
1115 // region append-to-stream
16+ ObjectMapper objectMapper = new ObjectMapper ();
17+
1218 EventData eventData = EventData
1319 .builderAsJson (
1420 UUID .randomUUID (),
1521 "some-event" ,
16- new TestEvent (
17- "1" ,
18- "some value"
19- ))
22+ objectMapper .writeValueAsBytes (new TestEvent ("1" , "some value" ))
23+ )
2024 .build ();
2125
2226 AppendToStreamOptions options = AppendToStreamOptions .get ()
@@ -27,16 +31,15 @@ private static void appendToStream(KurrentDBClient client) throws ExecutionExcep
2731 // endregion append-to-stream
2832 }
2933
30- private static void appendWithSameId (KurrentDBClient client ) throws ExecutionException , InterruptedException {
34+ private static void appendWithSameId (KurrentDBClient client ) throws ExecutionException , InterruptedException , JsonProcessingException {
3135 // region append-duplicate-event
36+ ObjectMapper objectMapper = new ObjectMapper ();
37+
3238 EventData eventData = EventData
3339 .builderAsJson (
3440 UUID .randomUUID (),
3541 "some-event" ,
36- new TestEvent (
37- "1" ,
38- "some value"
39- ))
42+ objectMapper .writeValueAsBytes (new TestEvent ("1" , "some value" )))
4043 .build ();
4144
4245 AppendToStreamOptions options = AppendToStreamOptions .get ()
@@ -51,26 +54,22 @@ private static void appendWithSameId(KurrentDBClient client) throws ExecutionExc
5154 // endregion append-duplicate-event
5255 }
5356
54- private static void appendWithNoStream (KurrentDBClient client ) throws ExecutionException , InterruptedException {
57+ private static void appendWithNoStream (KurrentDBClient client ) throws ExecutionException , InterruptedException , JsonProcessingException {
5558 // region append-with-no-stream
59+ ObjectMapper objectMapper = new ObjectMapper ();
60+
5661 EventData eventDataOne = EventData
5762 .builderAsJson (
5863 UUID .randomUUID (),
5964 "some-event" ,
60- new TestEvent (
61- "1" ,
62- "some value"
63- ))
65+ objectMapper .writeValueAsBytes (new TestEvent ("1" , "some value" )))
6466 .build ();
6567
6668 EventData eventDataTwo = EventData
6769 .builderAsJson (
6870 UUID .randomUUID (),
6971 "some-event" ,
70- new TestEvent (
71- "2" ,
72- "some other value"
73- ))
72+ objectMapper .writeValueAsBytes (new TestEvent ("2" , "some other value" )))
7473 .build ();
7574
7675 AppendToStreamOptions options = AppendToStreamOptions .get ()
@@ -85,8 +84,9 @@ private static void appendWithNoStream(KurrentDBClient client) throws ExecutionE
8584 // endregion append-with-no-stream
8685 }
8786
88- private static void appendWithConcurrencyCheck (KurrentDBClient client ) throws ExecutionException , InterruptedException {
87+ private static void appendWithConcurrencyCheck (KurrentDBClient client ) throws ExecutionException , InterruptedException , JsonProcessingException {
8988 // region append-with-concurrency-check
89+ ObjectMapper objectMapper = new ObjectMapper ();
9090
9191 ReadStreamOptions readStreamOptions = ReadStreamOptions .get ()
9292 .forwards ()
@@ -99,20 +99,14 @@ private static void appendWithConcurrencyCheck(KurrentDBClient client) throws Ex
9999 .builderAsJson (
100100 UUID .randomUUID (),
101101 "some-event" ,
102- new TestEvent (
103- "1" ,
104- "clientOne"
105- ))
102+ objectMapper .writeValueAsBytes (new TestEvent ("1" , "clientOne" )))
106103 .build ();
107104
108105 EventData clientTwoData = EventData
109106 .builderAsJson (
110107 UUID .randomUUID (),
111108 "some-event" ,
112- new TestEvent (
113- "2" ,
114- "clientTwo"
115- ))
109+ objectMapper .writeValueAsBytes (new TestEvent ("2" , "clientTwo" )))
116110 .build ();
117111
118112
@@ -127,15 +121,14 @@ private static void appendWithConcurrencyCheck(KurrentDBClient client) throws Ex
127121 // endregion append-with-concurrency-check
128122 }
129123
130- public void appendOverridingUserCredentials (KurrentDBClient client ) throws ExecutionException , InterruptedException {
124+ public void appendOverridingUserCredentials (KurrentDBClient client ) throws ExecutionException , InterruptedException , JsonProcessingException {
125+ ObjectMapper objectMapper = new ObjectMapper ();
126+
131127 EventData eventData = EventData
132128 .builderAsJson (
133129 UUID .randomUUID (),
134130 "some-event" ,
135- new TestEvent (
136- "1" ,
137- "some value"
138- ))
131+ objectMapper .writeValueAsBytes (new TestEvent ("1" , "some value" )))
139132 .build ();
140133 //region overriding-user-credentials
141134 UserCredentials credentials = new UserCredentials ("admin" , "changeit" );
0 commit comments