File tree Expand file tree Collapse file tree 7 files changed +47
-7
lines changed
src/main/java/dev/luismachadoreis/flighttracker/server Expand file tree Collapse file tree 7 files changed +47
-7
lines changed Original file line number Diff line number Diff line change 1- version : ' 3.8'
21
32services :
43 redis :
Original file line number Diff line number Diff line change 143143 <artifactId >h2</artifactId >
144144 <scope >test</scope >
145145 </dependency >
146+
147+ <dependency >
148+ <groupId >com.fasterxml.jackson.datatype</groupId >
149+ <artifactId >jackson-datatype-jsr310</artifactId >
150+ </dependency >
146151 </dependencies >
147152
148153 <build >
Original file line number Diff line number Diff line change 1+ package dev .luismachadoreis .flighttracker .server .common .infrastructure ;
2+
3+ import com .fasterxml .jackson .databind .ObjectMapper ;
4+ import com .fasterxml .jackson .datatype .jsr310 .JavaTimeModule ;
5+ import org .springframework .context .annotation .Bean ;
6+ import org .springframework .context .annotation .Configuration ;
7+
8+ /**
9+ * Configuration for Jackson ObjectMapper.
10+ */
11+ @ Configuration
12+ public class JacksonConfig {
13+
14+ /**
15+ * Creates a new ObjectMapper with the JavaTimeModule registered.
16+ * @return the ObjectMapper
17+ */
18+ @ Bean
19+ public ObjectMapper objectMapper () {
20+ ObjectMapper objectMapper = new ObjectMapper ();
21+ objectMapper .registerModule (new JavaTimeModule ());
22+ return objectMapper ;
23+ }
24+
25+ }
Original file line number Diff line number Diff line change 22
33import com .fasterxml .jackson .core .JsonProcessingException ;
44import com .fasterxml .jackson .databind .ObjectMapper ;
5-
5+ import org . springframework . stereotype . Component ;
66/**
77 * Utility class for JSON serialization and deserialization.
88 */
9+ @ Component
910public class JsonUtils {
1011
11- private static final ObjectMapper objectMapper = new ObjectMapper ();
12+ private final ObjectMapper objectMapper ;
13+
14+ public JsonUtils (ObjectMapper objectMapper ) {
15+ this .objectMapper = objectMapper ;
16+ }
1217
1318 /**
1419 * Serializes an object to a JSON string.
1520 * @param object the object to serialize
1621 * @return the JSON string
1722 */
18- public static String toJson (Object object ) {
23+ public String toJson (Object object ) {
1924 try {
2025 return objectMapper .writeValueAsString (object );
2126 } catch (JsonProcessingException e ) {
Original file line number Diff line number Diff line change @@ -196,6 +196,7 @@ public void registerPingCreated() {
196196 this .aircraft .callsign (),
197197 this .position .latitude (),
198198 this .position .longitude (),
199+ this .vector .trueTrack (),
199200 this .position .geoAltitude (),
200201 this .position .baroAltitude (),
201202 this .position .onGround (),
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ public record PingCreated (
1515 Double latitude ,
1616 @ JsonProperty ("longitude" )
1717 Double longitude ,
18+ @ JsonProperty ("true_track" )
19+ Double trueTrack ,
1820 @ JsonProperty ("geo_altitude" )
1921 Double geoAltitude ,
2022 @ JsonProperty ("baro_altitude" )
Original file line number Diff line number Diff line change 1616public class PingEventPublisher {
1717
1818 private final MapUpdatesHandler mapUpdatesHandler ;
19-
19+ private final JsonUtils jsonUtils ;
20+
2021 /**
2122 * Constructor for PingEventPublisher.
2223 * @param mapUpdatesHandler the MapUpdatesHandler to publish to
24+ * @param jsonUtils the JsonUtils to use for serialization
2325 */
24- public PingEventPublisher (MapUpdatesHandler mapUpdatesHandler ) {
26+ public PingEventPublisher (MapUpdatesHandler mapUpdatesHandler , JsonUtils jsonUtils ) {
2527 this .mapUpdatesHandler = mapUpdatesHandler ;
28+ this .jsonUtils = jsonUtils ;
2629 }
2730
2831 /**
@@ -31,7 +34,7 @@ public PingEventPublisher(MapUpdatesHandler mapUpdatesHandler) {
3134 */
3235 @ TransactionalEventListener (phase = TransactionPhase .AFTER_COMMIT )
3336 public void handlePingCreated (PingCreated event ) {
34- mapUpdatesHandler .sendMessage (JsonUtils .toJson (event ));
37+ mapUpdatesHandler .sendMessage (jsonUtils .toJson (event ));
3538 }
3639
3740}
You can’t perform that action at this time.
0 commit comments