From 73b4e9a2c91f6cb8c386c883537bb72d691d836c Mon Sep 17 00:00:00 2001 From: niko Date: Fri, 14 Feb 2025 09:36:14 +0000 Subject: [PATCH] fix deserialize --- .../montaro/aria2/client/http/Aria2HttpProxy.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/cn/montaro/aria2/client/http/Aria2HttpProxy.java b/src/main/java/cn/montaro/aria2/client/http/Aria2HttpProxy.java index c1dd4fc..dbea336 100644 --- a/src/main/java/cn/montaro/aria2/client/http/Aria2HttpProxy.java +++ b/src/main/java/cn/montaro/aria2/client/http/Aria2HttpProxy.java @@ -79,11 +79,20 @@ public class Aria2HttpProxy implements InvocationHandler { } private Object deserialize(String json, Type resultType) { - if (resultType.equals(String.class)) { - return json; - } JsonObject jsonObject = JsonParser.parseString(json).getAsJsonObject(); JsonElement result = jsonObject.get("result"); + + if (Objects.isNull(result)) { + return null; + } + + if (resultType.equals(String.class)) { + if (result.isJsonPrimitive()) { + return result.getAsJsonPrimitive().getAsString(); + } + return json; + } + return gson.fromJson(result, resultType); }