]> nmode's Git Repositories - signal-cli/commitdiff
Add workaround for jsonrpc clients that send null params
authorAsamK <asamk@gmx.de>
Wed, 22 Dec 2021 18:18:42 +0000 (19:18 +0100)
committerAsamK <asamk@gmx.de>
Wed, 22 Dec 2021 18:18:42 +0000 (19:18 +0100)
src/main/java/org/asamk/signal/jsonrpc/JsonRpcReader.java
src/main/java/org/asamk/signal/jsonrpc/JsonRpcRequest.java

index 6e58b23c5f102eee049c98ca02b7cf1f5cca26b4..5b641266c8652aaf72007a3dd04b607fde00d62a 100644 (file)
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ContainerNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.fasterxml.jackson.databind.node.ValueNode;
 
 import org.asamk.signal.util.Util;
@@ -39,7 +40,7 @@ public class JsonRpcReader {
             if (message == null) break;
 
             if (message instanceof final JsonRpcRequest jsonRpcRequest) {
-                logger.debug("Received json rpc request, method: " + jsonRpcRequest.method);
+                logger.debug("Received json rpc request, method: " + jsonRpcRequest.getMethod());
                 final var response = handleRequest(requestHandler, jsonRpcRequest);
                 if (response != null) {
                     jsonRpcSender.sendResponse(response);
@@ -153,6 +154,10 @@ public class JsonRpcReader {
     }
 
     private JsonRpcRequest parseJsonRpcRequest(final JsonNode input) throws JsonRpcException {
+        if (input instanceof ObjectNode i && input.has("params") && input.get("params").isNull()) {
+            // Workaround for clients that send a null params field instead of omitting it
+            i.remove("params");
+        }
         JsonRpcRequest request;
         try {
             request = objectMapper.treeToValue(input, JsonRpcRequest.class);
index ac54c7b7e774d3d2dbba2c491768b46fc232aaff..8e7535ec36bba688943c8fa04e41b36907fc8cbb 100644 (file)
@@ -13,21 +13,21 @@ public final class JsonRpcRequest extends JsonRpcMessage {
     /**
      * A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".
      */
-    String jsonrpc;
+    private String jsonrpc;
 
     /**
      * A String containing the name of the method to be invoked.
      * Method names that begin with the word rpc followed by a period character (U+002E or ASCII 46)
      * are reserved for rpc-internal methods and extensions and MUST NOT be used for anything else.
      */
-    String method;
+    private String method;
 
     /**
      * A Structured value that holds the parameter values to be used during the invocation of the method.
      * This member MAY be omitted.
      */
     @JsonInclude(JsonInclude.Include.NON_NULL)
-    ContainerNode<?> params;
+    private ContainerNode<?> params;
 
     /**
      * An identifier established by the Client that MUST contain a String, Number, or NULL value if included.
@@ -35,7 +35,7 @@ public final class JsonRpcRequest extends JsonRpcMessage {
      * The value SHOULD normally not be Null and Numbers SHOULD NOT contain fractional parts
      */
     @JsonInclude(JsonInclude.Include.NON_NULL)
-    ValueNode id;
+    private ValueNode id;
 
     public static JsonRpcRequest forNotification(
             final String method, final ContainerNode<?> params, final ValueNode id