Class JsonRpc

java.lang.Object
org.jgrapes.webconsole.base.JsonRpc
Direct Known Subclasses:
WcJsonRpc

public class JsonRpc extends Object
A class that serializes/deserializes as a JSON RPC.
  • Constructor Details

    • JsonRpc

      public JsonRpc()
      Instantiates a new json rpc.
    • JsonRpc

      public JsonRpc(String method)
      Instantiates a new json rpc.
      Parameters:
      method - the method
  • Method Details

    • setParamTypes

      public static void setParamTypes(Class<? extends JsonRpc> clazz, Map<String,List<Type>> types)
      Specify the types of the parameters for specific methods.

      Used for deserialization.

      Parameters:
      clazz - the clazz
      types - the param types
    • addParamTypes

      public static void addParamTypes(Class<? extends JsonRpc> clazz, String method, List<Type> types)
      Adds the parameter types for the given method.

      Used for deserialization.

      Parameters:
      clazz - the clazz
      method - the method
      types - the types
    • id

      public Optional<com.fasterxml.jackson.databind.JsonNode> id()
      An optional request id.
      Returns:
      the id
    • setId

      public JsonRpc setId(Number id)
      Sets the id.
      Parameters:
      id - the id
      Returns:
      the json rpc
    • setId

      public JsonRpc setId(String id)
      Sets the id.
      Parameters:
      id - the id
      Returns:
      the json rpc
    • method

      public String method()
      The invoked method.
      Returns:
      the method
    • params

      public Object[] params()
      The parameters.
      Returns:
      the params
    • setParams

      public JsonRpc setParams(Object... params)
      Sets the params.
      Parameters:
      params - the params
      Returns:
      the json rpc
    • addParam

      public JsonRpc addParam(Object param)
      Adds the param.
      Parameters:
      param - the param
      Returns:
      the json rpc
    • asString

      public String asString(int index)
      Returns the parameter’s value as string.
      Parameters:
      index - the index
      Returns:
      the string
    • param

      public <T> T param(int index)
      Returns the parameter’s value as the requested type.
      Type Parameters:
      T - the generic type
      Parameters:
      index - the index
      Returns:
      the string
    • streamOf

      public <T> Stream<T> streamOf(Class<T> cls, int index)
      Returns the parameter’s value as stream.
      Type Parameters:
      T - the generic type
      Parameters:
      cls - the class of the stream elements
      index - the index of the parameter
      Returns:
      the stream
    • toString

      public String toString()
      To string.
      Overrides:
      toString in class Object
      Returns:
      the string