From 9bc4c77ccbe6676da6b0de9c496e3c81707de59f Mon Sep 17 00:00:00 2001 From: Maxim Smirnov Date: Sat, 8 Jun 2024 14:06:15 +0400 Subject: [PATCH] Added temporary solution for Employee strucutre --- .../ru/livetex/sdk/logic/EntityMapper.java | 54 ++++++++----------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/sdk/src/main/java/ru/livetex/sdk/logic/EntityMapper.java b/sdk/src/main/java/ru/livetex/sdk/logic/EntityMapper.java index 6be4b1b..7bc1dd8 100644 --- a/sdk/src/main/java/ru/livetex/sdk/logic/EntityMapper.java +++ b/sdk/src/main/java/ru/livetex/sdk/logic/EntityMapper.java @@ -39,6 +39,7 @@ public class EntityMapper { .registerTypeAdapter(BaseEntity.class, new LivetexTypeModelDeserializer()) .registerTypeAdapter(GenericMessage.class, new LivetexGenericMessageDeserializer()) .registerTypeAdapter(Creator.class, new LivetexCreatorDeserializer()) + .registerTypeAdapter(DialogState.class, new LivetexDialogStateDeserializer()) .create(); public BaseEntity toEntity(String jsonStr) { @@ -59,12 +60,6 @@ public BaseEntity deserialize(final JsonElement json, final Type typeOfT, final case DialogState.TYPE: { return gson.fromJson(json, DialogState.class); } -// case TextMessage.TYPE: { -// return parseTextMessage(json); -// } -// case FileMessage.TYPE: { -// return parseFileMessage(json); -// } case TypingEvent.TYPE: { return gson.fromJson(json, TypingEvent.class); } @@ -85,31 +80,6 @@ public BaseEntity deserialize(final JsonElement json, final Type typeOfT, final } case HistoryEntity.TYPE: { HistoryEntity history = gson.fromJson(json, HistoryEntity.class); - -// JsonArray messages = jsonObject.getAsJsonArray("messages"); -// -// for (int i = 0; i < messages.size(); i++) { -// JsonElement message = messages.get(i); -// -// String msgType = message.getAsJsonObject().get("type").getAsString(); -// GenericMessage msg = null; -// -// switch (msgType) { -// case TextMessage.TYPE: { -// msg = parseTextMessage(message); -// break; -// } -// case FileMessage.TYPE: { -// msg = parseFileMessage(message); -// break; -// } -// } -// -// if (msg != null) { -// history.messages.add(msg); -// } -// } - return history; } case EmployeeTypingEvent.TYPE: { @@ -162,6 +132,10 @@ public Creator deserialize(JsonElement json, Type typeOfT, JsonDeserializationCo switch (creatorType) { case Employee.TYPE: { + if (obj.has("employee")) { + // temporary solution + return gson.fromJson(obj.get("employee"), Employee.class); + } return gson.fromJson(obj, Employee.class); } case Visitor.TYPE: { @@ -177,4 +151,22 @@ public Creator deserialize(JsonElement json, Type typeOfT, JsonDeserializationCo return null; } } + + static class LivetexDialogStateDeserializer implements JsonDeserializer { + @Override + public DialogState deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + JsonObject obj = json.getAsJsonObject(); + Gson tempGson = new GsonBuilder().create(); + DialogState result = tempGson.fromJson(json, DialogState.class); + + + JsonObject employee = obj.get("employee").getAsJsonObject(); + if (employee.has("employee")) { + // temporary solution + result.employee = gson.fromJson(employee.get("employee"), Employee.class); + } + + return result; + } + } }