From b0a3a919b7f6f82cf2afa780132dfefeddf78418 Mon Sep 17 00:00:00 2001 From: Thorsten Ortlepp Date: Tue, 7 May 2024 00:07:36 +0200 Subject: omit empty notifications --- .../java/eu/ortlepp/notificationsender/NotificationHandler.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/main/java/eu/ortlepp/notificationsender/NotificationHandler.java') diff --git a/src/main/java/eu/ortlepp/notificationsender/NotificationHandler.java b/src/main/java/eu/ortlepp/notificationsender/NotificationHandler.java index 17b4a46..6a93992 100644 --- a/src/main/java/eu/ortlepp/notificationsender/NotificationHandler.java +++ b/src/main/java/eu/ortlepp/notificationsender/NotificationHandler.java @@ -78,7 +78,7 @@ public class NotificationHandler implements RequestHandler, /** - * Extract the notifications from the input JSON. + * Extract the notifications from the input JSON. Omit empty notifications. * * @param body The input JSON * @return The extracted messages; empty list if an error occurred while parsing the JSON @@ -87,7 +87,9 @@ public class NotificationHandler implements RequestHandler, try { Notifications notifications = new ObjectMapper().readValue(body.toString(), Notifications.class); - return Arrays.asList(notifications.messages()); + var messages = new ArrayList<>(Arrays.asList(notifications.messages())); + messages.removeIf(message -> message.trim().isEmpty()); + return messages; } catch (JsonProcessingException ex) { logger.log("parsing input JSON failed : " + ex.getMessage()); return new ArrayList<>(); -- cgit v1.2.3