From c25515f414aba8ec776dc13663567cf9f84d0a08 Mon Sep 17 00:00:00 2001 From: spoonman01 Date: Wed, 27 Nov 2024 11:08:57 +0100 Subject: [PATCH 1/2] fix(json data deserialization) #WPB-12153 * Bump version to 1.7.2 --- pom.xml | 2 +- .../com/wire/xenon/backend/models/Payload.java | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 9952a23..450bfd6 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.wire xenon - 1.7.1 + 1.7.2 Xenon Base Wire Bots Library diff --git a/src/main/java/com/wire/xenon/backend/models/Payload.java b/src/main/java/com/wire/xenon/backend/models/Payload.java index 44aa5a9..86fd9f2 100644 --- a/src/main/java/com/wire/xenon/backend/models/Payload.java +++ b/src/main/java/com/wire/xenon/backend/models/Payload.java @@ -109,14 +109,14 @@ public Data deserialize(JsonParser jp, DeserializationContext ctxt) throws IOExc JsonNode node = jp.readValueAsTree(); if (node.isObject()) { Data data = new Data(); - data.sender = node.get("sender").asText(); - data.recipient = node.get("recipient").asText(); - data.text = node.get("text").asText(); - data.userIds = jp.getCodec().readValue(node.get("qualified_user_ids").traverse(jp.getCodec()), new TypeReference>() {}); - data.users = jp.getCodec().readValue(node.get("users").traverse(jp.getCodec()), new TypeReference>() {}); - data.name = node.get("name").asText(); - data.creator = node.get("creator").isTextual() ? UUID.fromString(node.get("creator").asText()) : null; - data.members = jp.getCodec().readValue(node.get("members").traverse(jp.getCodec()), Members.class); + data.sender = node.has("sender") ? node.get("sender").asText() : null; + data.recipient = node.has("recipient") ? node.get("recipient").asText() : null; + data.text = node.has("text") ? node.get("text").asText() : null; + data.userIds = node.has("qualified_user_ids") ? jp.getCodec().readValue(node.get("qualified_user_ids").traverse(jp.getCodec()), new TypeReference>() {}): null; + data.users = node.has("users") ? jp.getCodec().readValue(node.get("users").traverse(jp.getCodec()), new TypeReference>() {}) : null; + data.name = node.has("name") ? node.get("name").asText() : null; + data.creator = node.has("creator") && node.get("creator").isTextual() ? UUID.fromString(node.get("creator").asText()) : null; + data.members = node.has("members") ? jp.getCodec().readValue(node.get("members").traverse(jp.getCodec()), Members.class) : null; return data; } else if (node.isTextual()) { Data data = new Data(); From 19cc1e0643f5d3fefe63ab205e746eb837b500ea Mon Sep 17 00:00:00 2001 From: spoonman01 Date: Wed, 27 Nov 2024 11:37:16 +0100 Subject: [PATCH 2/2] Deserialize no users in Payload as empty list --- src/main/java/com/wire/xenon/backend/models/Payload.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/wire/xenon/backend/models/Payload.java b/src/main/java/com/wire/xenon/backend/models/Payload.java index 86fd9f2..368ba02 100644 --- a/src/main/java/com/wire/xenon/backend/models/Payload.java +++ b/src/main/java/com/wire/xenon/backend/models/Payload.java @@ -29,6 +29,7 @@ import javax.validation.constraints.NotNull; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -112,8 +113,8 @@ public Data deserialize(JsonParser jp, DeserializationContext ctxt) throws IOExc data.sender = node.has("sender") ? node.get("sender").asText() : null; data.recipient = node.has("recipient") ? node.get("recipient").asText() : null; data.text = node.has("text") ? node.get("text").asText() : null; - data.userIds = node.has("qualified_user_ids") ? jp.getCodec().readValue(node.get("qualified_user_ids").traverse(jp.getCodec()), new TypeReference>() {}): null; - data.users = node.has("users") ? jp.getCodec().readValue(node.get("users").traverse(jp.getCodec()), new TypeReference>() {}) : null; + data.userIds = node.has("qualified_user_ids") ? jp.getCodec().readValue(node.get("qualified_user_ids").traverse(jp.getCodec()), new TypeReference>() {}): new ArrayList<>(); + data.users = node.has("users") ? jp.getCodec().readValue(node.get("users").traverse(jp.getCodec()), new TypeReference>() {}) : new ArrayList<>(); data.name = node.has("name") ? node.get("name").asText() : null; data.creator = node.has("creator") && node.get("creator").isTextual() ? UUID.fromString(node.get("creator").asText()) : null; data.members = node.has("members") ? jp.getCodec().readValue(node.get("members").traverse(jp.getCodec()), Members.class) : null;