Skip to content

Commit

Permalink
Add json even deserialization to websockets
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdgeisler committed Nov 29, 2022
1 parent 6787c19 commit 87ec04b
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.dvdgeisler.iot.dirigera.client.examples.websockets;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.dvdgeisler.iot.dirigera.client.api.DirigeraApi;
import de.dvdgeisler.iot.dirigera.client.api.http.ClientApi;
import org.slf4j.Logger;
Expand All @@ -19,12 +21,18 @@ public class WebSockets {
private final static Logger log = LoggerFactory.getLogger(WebSockets.class);

@Bean
public CommandLineRunner run(final DirigeraApi api, final ClientApi capi) {
public CommandLineRunner run(final DirigeraApi api, final ClientApi capi, final ObjectMapper json) {

return (String... args) -> {
api.pairIfRequired().block(); // pair gateway if required

capi.websocket(message -> log.debug("Received websocket message: {}", message));
capi.websocket(event -> {
try {
log.debug("Received websocket message: {}", json.writeValueAsString(event));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}).block();
};
}

Expand Down

0 comments on commit 87ec04b

Please sign in to comment.