diff --git a/Quickstart/Java/esdb-sample-springboot/build.gradle b/Quickstart/Java/esdb-sample-springboot/build.gradle
index cf3c28a..c5c5586 100644
--- a/Quickstart/Java/esdb-sample-springboot/build.gradle
+++ b/Quickstart/Java/esdb-sample-springboot/build.gradle
@@ -19,7 +19,7 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
- implementation 'com.eventstore:db-client-java:5.2.0'
+ implementation 'com.eventstore:db-client-java:5.3.0'
implementation 'com.google.code.gson:gson:2.10.1'
}
diff --git a/Quickstart/Java/esdb-sample-springboot/pom.xml b/Quickstart/Java/esdb-sample-springboot/pom.xml
index 1d72c3e..1a7c937 100644
--- a/Quickstart/Java/esdb-sample-springboot/pom.xml
+++ b/Quickstart/Java/esdb-sample-springboot/pom.xml
@@ -28,7 +28,7 @@
com.eventstore
db-client-java
- 5.2.0
+ 5.3.0
com.google.code.gson
diff --git a/Quickstart/Java/esdb-sample-springboot/src/main/java/com/example/esdbsamplespringboot/HelloWorldApplication.java b/Quickstart/Java/esdb-sample-springboot/src/main/java/com/example/esdbsamplespringboot/HelloWorldApplication.java
index 6768079..f7ddd3e 100644
--- a/Quickstart/Java/esdb-sample-springboot/src/main/java/com/example/esdbsamplespringboot/HelloWorldApplication.java
+++ b/Quickstart/Java/esdb-sample-springboot/src/main/java/com/example/esdbsamplespringboot/HelloWorldApplication.java
@@ -1,11 +1,18 @@
package com.example.esdbsamplespringboot;
+import com.google.gson.Gson;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class HelloWorldApplication {
- public static void main(String[] args) {
- SpringApplication.run(HelloWorldApplication.class, args);
- }
+ public static void main(String[] args) {
+ SpringApplication.run(HelloWorldApplication.class, args);
+ }
+
+ @Bean
+ public Gson GsonMapper() {
+ return new Gson();
+ }
}
diff --git a/Quickstart/Java/esdb-sample-springboot/src/main/java/com/example/esdbsamplespringboot/HelloWorldController.java b/Quickstart/Java/esdb-sample-springboot/src/main/java/com/example/esdbsamplespringboot/HelloWorldController.java
index 5083d8e..080c37e 100644
--- a/Quickstart/Java/esdb-sample-springboot/src/main/java/com/example/esdbsamplespringboot/HelloWorldController.java
+++ b/Quickstart/Java/esdb-sample-springboot/src/main/java/com/example/esdbsamplespringboot/HelloWorldController.java
@@ -9,28 +9,32 @@
import org.springframework.web.bind.annotation.ResponseBody;
import com.eventstore.dbclient.*;
import com.google.gson.Gson;
+
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@Controller
public class HelloWorldController {
private static final String VISITORS_STREAM = "visitors-stream";
- private static final Gson gson = new Gson();
private final EventStoreDBClient eventStore;
+ private final Gson gsonMapper;
@Autowired
- public HelloWorldController(EventStoreDBClient eventStore) {
+ public HelloWorldController(EventStoreDBClient eventStore, Gson gsonMapper) {
this.eventStore = eventStore;
+ this.gsonMapper = gsonMapper;
}
@ResponseBody
- @GetMapping("/hello-world")
- public ResponseEntity> sayHello(@RequestParam(name="visitor", required=false, defaultValue="Visitor") String visitor) {
+ @GetMapping("/hello-world")
+ public ResponseEntity> sayHello(@RequestParam(name = "visitor", required = false, defaultValue = "Visitor") String visitor) {
try {
VisitorGreeted visitorGreeted = new VisitorGreeted(visitor);
+ byte[] vgBytes = gsonMapper.toJson(visitorGreeted).getBytes();
EventData event = EventData
- .builderAsJson("VisitorGreeted", visitorGreeted)
+ .builderAsJson("VisitorGreeted", vgBytes)
.build();
WriteResult writeResult = eventStore
@@ -45,7 +49,7 @@ public ResponseEntity> sayHello(@RequestParam(name="visitor", required=false,
List visitorsGreeted = new ArrayList<>();
for (ResolvedEvent re : eventStream.getEvents()) {
- VisitorGreeted vg = gson.fromJson(
+ VisitorGreeted vg = gsonMapper.fromJson(
new String(re.getOriginalEvent().getEventData()),
VisitorGreeted.class);
@@ -61,7 +65,7 @@ public ResponseEntity> sayHello(@RequestParam(name="visitor", required=false,
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
}
- }
+ }
static class VisitorGreeted {
private String visitor;