Class NamedParamsRetriever
- java.lang.Object
-
- com.thetransactioncompany.jsonrpc2.util.ParamsRetriever
-
- com.thetransactioncompany.jsonrpc2.util.NamedParamsRetriever
-
public class NamedParamsRetriever extends ParamsRetriever
Utility class for retrieving JSON-RPC 2.0 named parameters (key-value pairs packed into a JSON Object).Provides a set of getter methods according to the expected parameter type (number, string, etc.) and whether the parameter is mandatory or optional:
getXXX(param_name)for mandatory parameters, whereXXXis the expected parameter type.getOptXXX(param_name, default_value)for optional parameters, specifying a default value.
There are also generic getter methods that let you do the type conversion yourself.
If a parameter cannot be retrieved, e.g. due to a missing mandatory parameter or bad type, a
JSONRPC2Error.INVALID_PARAMSexception is thrown.Example: suppose you have a method with 3 named parameters "name", "age" and "sex", where the last is optional and defaults to "female":
// Parse received request string JSONRPC2Request request = null; try { request = JSONRPC2Request.parse(jsonString); } catch (JSONRPC2ParseException e) { // handle exception... } // Create a new retriever for named parameters Map params = (Map)request.getParams(); NamedParamsRetriever r = new NamedParamsRetriever(params); try { // Extract "name" string parameter String name = r.getString("name"); // Extract "age" integer parameter int age = r.getInt("age"); // Extract optional "sex" string parameter which defaults to "female" String sex = r.getOptString("sex", "female"); } catch (JSONRPC2Error e) { // A JSONRPC2Error.INVALID_PARAMS will be thrown to indicate // an unexpected parameter type or a missing mandatory parameter. // You can use it straight away to create the appropriate // JSON-RPC 2.0 error response. JSONRPC2Response response = new JSONRPC2Response(e, null); }- Author:
- Vladimir Dzhuvinov
-
-
Constructor Summary
Constructors Constructor Description NamedParamsRetriever(Map<String,Object> params)Creates a new named parameters retriever from the specified key-value map.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidensureParam(String name)Throws aJSONRPC2Error.INVALID_PARAMSexception if there is no parameter by the specified name.<T> voidensureParam(String name, Class<T> clazz)Throws aJSONRPC2Error.INVALID_PARAMSexception if there is no parameter by the specified name, its value isnull, or its type doesn't map to the specified.<T> voidensureParam(String name, Class<T> clazz, boolean allowNull)Throws aJSONRPC2Error.INVALID_PARAMSexception if there is no parameter by the specified name or its type doesn't map to the specified.voidensureParameter(String name)Deprecated.<T> voidensureParameter(String name, Class<T> clazz)Deprecated.<T> voidensureParameter(String name, Class<T> clazz, boolean allowNull)Deprecated.voidensureParameters(String[] mandatoryNames)Deprecated.voidensureParameters(String[] mandatoryNames, String[] optionalNames)Deprecated.voidensureParams(String[] mandatoryNames)Throws aJSONRPC2Error.INVALID_PARAMSif the specified names aren't present in the parameters, or names outside the specified are contained.voidensureParams(String[] mandatoryNames, String[] optionalNames)Throws aJSONRPC2Error.INVALID_PARAMSif the specified mandatory names aren't contained in the parameters, or names outside the specified mandatory and optional are present.Objectget(String name)Retrieves the specified parameter which can be of any type.<T> Tget(String name, Class<T> clazz)Retrieves the specified parameter which must map to the provided class (use the appropriate wrapper class for primitive types).<T> Tget(String name, Class<T> clazz, boolean allowNull)Retrieves the specified parameter which must map to the provided class (use the appropriate wrapper class for primitive types).booleangetBoolean(String name)Retrieves the specified boolean (maps from JSON true/false) parameter.doublegetDouble(String name)Retrieves the specified numeric parameter as adouble.<T extends Enum<T>>
TgetEnum(String name, Class<T> enumClass)Retrieves the specified enumerated parameter (from a JSON string that has a predefined set of possible values).<T extends Enum<T>>
TgetEnum(String name, Class<T> enumClass, boolean ignoreCase)Retrieves the specified enumerated parameter (from a JSON string that has a predefined set of possible values), allowing for a case insensitive match.StringgetEnumString(String name, String[] enumStrings)Retrieves the specified enumerated string parameter.StringgetEnumString(String name, String[] enumStrings, boolean ignoreCase)Retrieves the specified enumerated string parameter, allowing for a case insenstive match.floatgetFloat(String name)Retrieves the specified numeric parameter as afloat.intgetInt(String name)Retrieves the specified numeric parameter as anint.List<Object>getList(String name)Retrieves the specified list (maps from JSON array) parameter.List<Object>getList(String name, boolean allowNull)Retrieves the specified list (maps from JSON array) parameter.longgetLong(String name)Retrieves the specified numeric parameter as along.Map<String,Object>getMap(String name)Retrieves the specified map (maps from JSON object) parameter.Map<String,Object>getMap(String name, boolean allowNull)Retrieves the specified map (maps from JSON object) parameter.String[]getNames()Returns the names of all available parameters.<T> TgetOpt(String name, Class<T> clazz, boolean allowNull, T defaultValue)Retrieves the specified optional parameter which must map to the provided class (use the appropriate wrapper class for primitive types).<T> TgetOpt(String name, Class<T> clazz, T defaultValue)Retrieves the specified optional parameter which must map to the provided class (use the appropriate wrapper class for primitive types).booleangetOptBoolean(String name, boolean defaultValue)Retrieves the specified optional boolean (maps from JSON true/false) parameter.doublegetOptDouble(String name, double defaultValue)Retrieves the specified optional numeric parameter as adouble.<T extends Enum<T>>
TgetOptEnum(String name, Class<T> enumClass, T defaultValue)Retrieves the specified optional enumerated parameter (from a JSON string that has a predefined set of possible values).<T extends Enum<T>>
TgetOptEnum(String name, Class<T> enumClass, T defaultValue, boolean ignoreCase)Retrieves the specified optional enumerated parameter (from a JSON string that has a predefined set of possible values), allowing for a case insenstive match.StringgetOptEnumString(String name, String[] enumStrings, String defaultValue)Retrieves the specified optional enumerated string parameter.StringgetOptEnumString(String name, String[] enumStrings, String defaultValue, boolean ignoreCase)Retrieves the specified optional enumerated string parameter, allowing for a case insenstive match.floatgetOptFloat(String name, float defaultValue)Retrieves the specified optional numeric parameter as afloat.intgetOptInt(String name, int defaultValue)Retrieves the specified optional numeric parameter as anint.List<Object>getOptList(String name, boolean allowNull, List<Object> defaultValue)Retrieves the specified optional list (maps from JSON array) parameter.List<Object>getOptList(String name, List<Object> defaultValue)Retrieves the specified optional list (maps from JSON array) parameter.longgetOptLong(String name, long defaultValue)Retrieves the specified optional numeric parameter as along.Map<String,Object>getOptMap(String name, boolean allowNull, Map<String,Object> defaultValue)Retrieves the specified optional map (maps from JSON object) parameter.Map<String,Object>getOptMap(String name, Map<String,Object> defaultValue)Retrieves the specified optional map (maps from JSON object) parameter.StringgetOptString(String name, boolean allowNull, String defaultValue)Retrieves the specified optional string parameter.StringgetOptString(String name, String defaultValue)Retrieves the specified optional string parameter.String[]getOptStringArray(String name, boolean allowNull, String[] defaultValue)Retrieves the specified optional string array (maps from JSON array of strings) parameter.String[]getOptStringArray(String name, String[] defaultValue)Retrieves the specified optional string array (maps from JSON array of strings) parameter.Map<String,Object>getParams()Gets the named parameters for this retriever.StringgetString(String name)Retrieves the specified string parameter.StringgetString(String name, boolean allowNull)Retrieves the specified string parameter.String[]getStringArray(String name)Retrieves the specified string array (maps from JSON array of strings) parameter.String[]getStringArray(String name, boolean allowNull)Retrieves the specified string array (maps from JSON array of strings) parameter.booleanhasParam(String name)Returnstrueif a parameter by the specified name exists, elsefalse.booleanhasParameter(String name)Deprecated.booleanhasParameters(String[] names)Deprecated.booleanhasParameters(String[] mandatoryNames, String[] optionalNames)Deprecated.booleanhasParams(String[] names)Returnstrueif the parameters by the specified names exist, elsefalse.booleanhasParams(String[] mandatoryNames, String[] optionalNames)Returnstrueif the parameters by the specified mandatory names exist,falseif any mandatory name is missing or a name outside the mandatory and optional is present.intsize()Returns the parameter count.-
Methods inherited from class com.thetransactioncompany.jsonrpc2.util.ParamsRetriever
getEnumStringMatch, getEnumStringMatch
-
-
-
-
Method Detail
-
getParams
public Map<String,Object> getParams()
Gets the named parameters for this retriever.- Returns:
- The named parameters.
-
size
public int size()
Description copied from class:ParamsRetrieverReturns the parameter count.- Specified by:
sizein classParamsRetriever- Returns:
- The parameters count.
-
hasParam
public boolean hasParam(String name)
Returnstrueif a parameter by the specified name exists, elsefalse.- Parameters:
name- The parameter name.- Returns:
trueif the parameter exists, elsefalse.
-
hasParameter
@Deprecated public boolean hasParameter(String name)
Deprecated.- See Also:
hasParam(java.lang.String)
-
hasParams
public boolean hasParams(String[] names)
Returnstrueif the parameters by the specified names exist, elsefalse.- Parameters:
names- The parameter names. Must not benull.- Returns:
trueif the parameters exist, elsefalse.
-
hasParameters
@Deprecated public boolean hasParameters(String[] names)
Deprecated.- See Also:
hasParams(String[])
-
hasParams
public boolean hasParams(String[] mandatoryNames, String[] optionalNames)
Returnstrueif the parameters by the specified mandatory names exist,falseif any mandatory name is missing or a name outside the mandatory and optional is present.- Parameters:
mandatoryNames- The expected mandatory parameter names. Must not benull.optionalNames- The expected optional parameter names, empty array ornullif none.- Returns:
trueif the specified mandatory names and only any of the optional are present, elsefalse.
-
hasParameters
@Deprecated public boolean hasParameters(String[] mandatoryNames, String[] optionalNames)
Deprecated.- See Also:
hasParams(String[], String[])
-
getNames
public String[] getNames()
Returns the names of all available parameters.- Returns:
- The parameter names.
-
ensureParams
public void ensureParams(String[] mandatoryNames) throws JSONRPC2Error
Throws aJSONRPC2Error.INVALID_PARAMSif the specified names aren't present in the parameters, or names outside the specified are contained.You may use this method to a fire a proper JSON-RPC 2.0 error on a missing or unexpected mandatory parameter name.
- Parameters:
mandatoryNames- The expected parameter names. Must not benull.- Throws:
JSONRPC2Error- On a missing parameter name or names outside the specified (JSONRPC2Error.INVALID_PARAMS).
-
ensureParameters
@Deprecated public void ensureParameters(String[] mandatoryNames) throws JSONRPC2Error
Deprecated.- Throws:
JSONRPC2Error- See Also:
ensureParams(String[])
-
ensureParams
public void ensureParams(String[] mandatoryNames, String[] optionalNames) throws JSONRPC2Error
Throws aJSONRPC2Error.INVALID_PARAMSif the specified mandatory names aren't contained in the parameters, or names outside the specified mandatory and optional are present.You may use this method to a fire a proper JSON-RPC 2.0 error on a missing or unexpected mandatory parameter name.
- Parameters:
mandatoryNames- The expected mandatory parameter names. Must not benull.optionalNames- The expected optional parameter names, empty array ornullif none.- Throws:
JSONRPC2Error- On a missing mandatory parameter name or names outside the specified mandatory and optional (JSONRPC2Error.INVALID_PARAMS).
-
ensureParameters
@Deprecated public void ensureParameters(String[] mandatoryNames, String[] optionalNames) throws JSONRPC2Error
Deprecated.- Throws:
JSONRPC2Error- See Also:
ensureParams(String[], String[])
-
ensureParam
public void ensureParam(String name) throws JSONRPC2Error
Throws aJSONRPC2Error.INVALID_PARAMSexception if there is no parameter by the specified name.You may use this method to fire the proper JSON-RPC 2.0 error on a missing mandatory parameter.
- Parameters:
name- The parameter name.- Throws:
JSONRPC2Error- On a missing parameter (JSONRPC2Error.INVALID_PARAMS).
-
ensureParameter
@Deprecated public void ensureParameter(String name) throws JSONRPC2Error
Deprecated.- Throws:
JSONRPC2Error- See Also:
ensureParam(String)
-
ensureParam
public <T> void ensureParam(String name, Class<T> clazz) throws JSONRPC2Error
Throws aJSONRPC2Error.INVALID_PARAMSexception if there is no parameter by the specified name, its value isnull, or its type doesn't map to the specified.You may use this method to fire the proper JSON-RPC 2.0 error on a missing or badly-typed mandatory parameter.
- Parameters:
name- The parameter name.clazz- The corresponding Java class that the parameter should map to (any one of the return types of thegetXXX()getter methods. Set toObject.classto allow any type. Must not benull.- Throws:
JSONRPC2Error- On a missing parameter,nullvalue or bad type (JSONRPC2Error.INVALID_PARAMS).
-
ensureParameter
@Deprecated public <T> void ensureParameter(String name, Class<T> clazz) throws JSONRPC2Error
Deprecated.- Throws:
JSONRPC2Error- See Also:
ensureParam(String, Class)
-
ensureParam
public <T> void ensureParam(String name, Class<T> clazz, boolean allowNull) throws JSONRPC2Error
Throws aJSONRPC2Error.INVALID_PARAMSexception if there is no parameter by the specified name or its type doesn't map to the specified.You may use this method to fire the proper JSON-RPC 2.0 error on a missing or badly-typed mandatory parameter.
- Parameters:
name- The parameter name.clazz- The corresponding Java class that the parameter should map to (any one of the return types of thegetXXX()getter methods. Set toObject.classto allow any type. Must not benull.allowNull- Iftrueallows anullparameter value.- Throws:
JSONRPC2Error- On a missing parameter or bad type (JSONRPC2Error.INVALID_PARAMS).
-
ensureParameter
@Deprecated public <T> void ensureParameter(String name, Class<T> clazz, boolean allowNull) throws JSONRPC2Error
Deprecated.- Throws:
JSONRPC2Error- See Also:
ensureParam(String, Class, boolean)
-
get
public Object get(String name) throws JSONRPC2Error
Retrieves the specified parameter which can be of any type. Use this generic getter if you want to cast the value yourself. Otherwise look at the typedget*methods.- Parameters:
name- The parameter name.- Returns:
- The parameter value.
- Throws:
JSONRPC2Error- On a missing parameter (JSONRPC2Error.INVALID_PARAMS).
-
get
public <T> T get(String name, Class<T> clazz) throws JSONRPC2Error
Retrieves the specified parameter which must map to the provided class (use the appropriate wrapper class for primitive types).- Parameters:
name- The parameter name.clazz- The corresponding Java class that the parameter should map to (any one of the return types of thegetXXX()getter methods. Set toObject.classto allow any type. Must not benull.- Returns:
- The parameter value.
- Throws:
JSONRPC2Error- On a missing parameter,nullvalue or bad type (JSONRPC2Error.INVALID_PARAMS).
-
get
public <T> T get(String name, Class<T> clazz, boolean allowNull) throws JSONRPC2Error
Retrieves the specified parameter which must map to the provided class (use the appropriate wrapper class for primitive types).- Parameters:
name- The parameter name.clazz- The corresponding Java class that the parameter should map to (any one of the return types of thegetXXX()getter methods. Set toObject.classto allow any type. Must not benull.allowNull- Iftrueallows anullparameter value.- Returns:
- The parameter value.
- Throws:
JSONRPC2Error- On a missing parameter or bad type (JSONRPC2Error.INVALID_PARAMS).
-
getOpt
public <T> T getOpt(String name, Class<T> clazz, T defaultValue) throws JSONRPC2Error
Retrieves the specified optional parameter which must map to the provided class (use the appropriate wrapper class for primitive types). If the parameter doesn't exist the method returns the specified default value.- Parameters:
name- The parameter name.clazz- The corresponding Java class that the parameter should map to (any one of the return types of thegetXXX()getter methods. Set toObject.classto allow any type. Must not benull.defaultValue- The default return value if the parameter doesn't exist. May benull.- Returns:
- The parameter value.
- Throws:
JSONRPC2Error- On a bad parameter type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getOpt
public <T> T getOpt(String name, Class<T> clazz, boolean allowNull, T defaultValue) throws JSONRPC2Error
Retrieves the specified optional parameter which must map to the provided class (use the appropriate wrapper class for primitive types). If the parameter doesn't exist the method returns the specified default value.- Parameters:
name- The parameter name.clazz- The corresponding Java class that the parameter should map to (any one of the return types of thegetXXX()getter methods. Set toObject.classto allow any type. Must not benull.allowNull- Iftrueallows anullparameter value.defaultValue- The default return value if the parameter doesn't exist. May benull.- Returns:
- The parameter value.
- Throws:
JSONRPC2Error- On a bad parameter type (JSONRPC2Error.INVALID_PARAMS).
-
getString
public String getString(String name) throws JSONRPC2Error
Retrieves the specified string parameter.- Parameters:
name- The parameter name.- Returns:
- The parameter value as a string.
- Throws:
JSONRPC2Error- On a missing parameter, bad type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getString
public String getString(String name, boolean allowNull) throws JSONRPC2Error
Retrieves the specified string parameter.- Parameters:
name- The parameter name.allowNull- Iftrueallows anullvalue.- Returns:
- The parameter value as a string.
- Throws:
JSONRPC2Error- On a missing parameter or bad type (JSONRPC2Error.INVALID_PARAMS).
-
getOptString
public String getOptString(String name, String defaultValue) throws JSONRPC2Error
Retrieves the specified optional string parameter. If it doesn't exist the method will return the specified default value.- Parameters:
name- The parameter name.defaultValue- The default return value if the parameter doesn't exist. May benull.- Returns:
- The parameter value as a string.
- Throws:
JSONRPC2Error- On a bad type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getOptString
public String getOptString(String name, boolean allowNull, String defaultValue) throws JSONRPC2Error
Retrieves the specified optional string parameter. If it doesn't exist the method will return the specified default value.- Parameters:
name- The parameter name.allowNull- Iftrueallows anullvalue.defaultValue- The default return value if the parameter doesn't exist. May benull.- Returns:
- The parameter value as a string.
- Throws:
JSONRPC2Error- On a bad type (JSONRPC2Error.INVALID_PARAMS).
-
getEnumString
public String getEnumString(String name, String[] enumStrings) throws JSONRPC2Error
Retrieves the specified enumerated string parameter.- Parameters:
name- The parameter name.enumStrings- The acceptable string values. Must not benull.- Returns:
- The parameter value as a string.
- Throws:
JSONRPC2Error- On a missing parameter, bad type or bad enumeration value (JSONRPC2Error.INVALID_PARAMS).
-
getEnumString
public String getEnumString(String name, String[] enumStrings, boolean ignoreCase) throws JSONRPC2Error
Retrieves the specified enumerated string parameter, allowing for a case insenstive match.- Parameters:
name- The parameter name.enumStrings- The acceptable string values. Must not benull.ignoreCase-truefor a case insensitive match.- Returns:
- The matching parameter value as a string.
- Throws:
JSONRPC2Error- On a missing parameter, bad type or bad enumeration value (JSONRPC2Error.INVALID_PARAMS).
-
getOptEnumString
public String getOptEnumString(String name, String[] enumStrings, String defaultValue) throws JSONRPC2Error
Retrieves the specified optional enumerated string parameter.- Parameters:
name- The parameter name.enumStrings- The acceptable string values. Must not benull.defaultValue- The default return value if the parameter doesn't exist. May benull.- Returns:
- The parameter value as a string.
- Throws:
JSONRPC2Error- On a bad type or bad enumeration value (JSONRPC2Error.INVALID_PARAMS).
-
getOptEnumString
public String getOptEnumString(String name, String[] enumStrings, String defaultValue, boolean ignoreCase) throws JSONRPC2Error
Retrieves the specified optional enumerated string parameter, allowing for a case insenstive match. If it doesn't exist the method will return the specified default value.- Parameters:
name- The parameter name.enumStrings- The acceptable string values. Must not benull.defaultValue- The default return value if the parameter doesn't exist. May benull.ignoreCase-truefor a case insensitive match.- Returns:
- The matching parameter value as a string.
- Throws:
JSONRPC2Error- On a bad type or bad enumeration value (JSONRPC2Error.INVALID_PARAMS).
-
getEnum
public <T extends Enum<T>> T getEnum(String name, Class<T> enumClass) throws JSONRPC2Error
Retrieves the specified enumerated parameter (from a JSON string that has a predefined set of possible values).- Parameters:
name- The parameter name.enumClass- An enumeration type with constant names representing the acceptable string values. Must not benull.- Returns:
- The matching enumeration constant.
- Throws:
JSONRPC2Error- On a missing parameter, bad type or bad enumeration value (JSONRPC2Error.INVALID_PARAMS).
-
getEnum
public <T extends Enum<T>> T getEnum(String name, Class<T> enumClass, boolean ignoreCase) throws JSONRPC2Error
Retrieves the specified enumerated parameter (from a JSON string that has a predefined set of possible values), allowing for a case insensitive match.- Parameters:
name- The parameter name.enumClass- An enumeration type with constant names representing the acceptable string values. Must not benull.ignoreCase- Iftruea case insensitive match against the acceptable constant names is performed.- Returns:
- The matching enumeration constant.
- Throws:
JSONRPC2Error- On a missing parameter, bad type or bad enumeration value (JSONRPC2Error.INVALID_PARAMS).
-
getOptEnum
public <T extends Enum<T>> T getOptEnum(String name, Class<T> enumClass, T defaultValue) throws JSONRPC2Error
Retrieves the specified optional enumerated parameter (from a JSON string that has a predefined set of possible values).- Parameters:
name- The parameter name.enumClass- An enumeration type with constant names representing the acceptable string values. Must not benull.defaultValue- The default return value if the parameter doesn't exist. May benull.- Returns:
- The matching enumeration constant.
- Throws:
JSONRPC2Error- On a bad type or bad enumeration value (JSONRPC2Error.INVALID_PARAMS).
-
getOptEnum
public <T extends Enum<T>> T getOptEnum(String name, Class<T> enumClass, T defaultValue, boolean ignoreCase) throws JSONRPC2Error
Retrieves the specified optional enumerated parameter (from a JSON string that has a predefined set of possible values), allowing for a case insenstive match. If it doesn't exist the method will return the specified default value.- Parameters:
name- The parameter name.enumClass- An enumeration type with constant names representing the acceptable string values. Must not benull.defaultValue- The default return value if the parameter doesn't exist. May benull.ignoreCase- Iftruea case insensitive match against the acceptable constant names is performed.- Returns:
- The matching enumeration constant.
- Throws:
JSONRPC2Error- On a bad type or bad enumeration value (JSONRPC2Error.INVALID_PARAMS).
-
getBoolean
public boolean getBoolean(String name) throws JSONRPC2Error
Retrieves the specified boolean (maps from JSON true/false) parameter.- Parameters:
name- The parameter name.- Returns:
- The parameter value as a
boolean. - Throws:
JSONRPC2Error- On a missing parameter, bad type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getOptBoolean
public boolean getOptBoolean(String name, boolean defaultValue) throws JSONRPC2Error
Retrieves the specified optional boolean (maps from JSON true/false) parameter. If it doesn't exist the method will return the specified default value.- Parameters:
name- The parameter name.defaultValue- The default return value if the parameter doesn't exist.- Returns:
- The parameter value as a
boolean. - Throws:
JSONRPC2Error- On a bad parameter type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getInt
public int getInt(String name) throws JSONRPC2Error
Retrieves the specified numeric parameter as anint.- Parameters:
name- The parameter name.- Returns:
- The parameter value as an
int. - Throws:
JSONRPC2Error- On a missing parameter, bad type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getOptInt
public int getOptInt(String name, int defaultValue) throws JSONRPC2Error
Retrieves the specified optional numeric parameter as anint. If it doesn't exist the method will return the specified default value.- Parameters:
name- The parameter name.defaultValue- The default return value if the parameter doesn't exist.- Returns:
- The parameter value as an
int. - Throws:
JSONRPC2Error- On a bad parameter type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getLong
public long getLong(String name) throws JSONRPC2Error
Retrieves the specified numeric parameter as along.- Parameters:
name- The parameter name.- Returns:
- The parameter value as a
long. - Throws:
JSONRPC2Error- On a missing parameter, bad type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getOptLong
public long getOptLong(String name, long defaultValue) throws JSONRPC2Error
Retrieves the specified optional numeric parameter as along. If it doesn't exist the method will return the specified default value.- Parameters:
name- The parameter name.defaultValue- The default return value if the parameter doesn't exist.- Returns:
- The parameter value as a long.
- Throws:
JSONRPC2Error- On a bad parameter type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getFloat
public float getFloat(String name) throws JSONRPC2Error
Retrieves the specified numeric parameter as afloat.- Parameters:
name- The parameter name.- Returns:
- The parameter value as a
float. - Throws:
JSONRPC2Error- On a missing parameter, bad type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getOptFloat
public float getOptFloat(String name, float defaultValue) throws JSONRPC2Error
Retrieves the specified optional numeric parameter as afloat. If it doesn't exist the method will return the specified default value.- Parameters:
name- The parameter name.defaultValue- The default return value if the parameter doesn't exist.- Returns:
- The parameter value as a
float. - Throws:
JSONRPC2Error- On a bad parameter type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getDouble
public double getDouble(String name) throws JSONRPC2Error
Retrieves the specified numeric parameter as adouble.- Parameters:
name- The parameter name.- Returns:
- The parameter value as a
double. - Throws:
JSONRPC2Error- On a missing parameter, bad type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getOptDouble
public double getOptDouble(String name, double defaultValue) throws JSONRPC2Error
Retrieves the specified optional numeric parameter as adouble. If it doesn't exist the method will return the specified default value.- Parameters:
name- The parameter name.defaultValue- The default return value if the parameter doesn't exist.- Returns:
- The parameter value as a
double. - Throws:
JSONRPC2Error- On a bad parameter type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getList
public List<Object> getList(String name) throws JSONRPC2Error
Retrieves the specified list (maps from JSON array) parameter.- Parameters:
name- The parameter name.- Returns:
- The parameter value as a list.
- Throws:
JSONRPC2Error- On a missing parameter, bad type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getList
public List<Object> getList(String name, boolean allowNull) throws JSONRPC2Error
Retrieves the specified list (maps from JSON array) parameter.- Parameters:
name- The parameter name.allowNull- Iftrueallows anullvalue.- Returns:
- The parameter value as a list.
- Throws:
JSONRPC2Error- On a missing parameter or bad type (JSONRPC2Error.INVALID_PARAMS).
-
getOptList
public List<Object> getOptList(String name, List<Object> defaultValue) throws JSONRPC2Error
Retrieves the specified optional list (maps from JSON array) parameter. If it doesn't exist the method will return the specified default value.- Parameters:
name- The parameter name.defaultValue- The default return value if the parameter doesn't exist. May benull.- Returns:
- The parameter value as a list.
- Throws:
JSONRPC2Error- On a bad parameter type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getOptList
public List<Object> getOptList(String name, boolean allowNull, List<Object> defaultValue) throws JSONRPC2Error
Retrieves the specified optional list (maps from JSON array) parameter. If it doesn't exist the method will return the specified default value.- Parameters:
name- The parameter name.allowNull- Iftrueallows anullvalue.defaultValue- The default return value if the parameter doesn't exist. May benull.- Returns:
- The parameter value as a list.
- Throws:
JSONRPC2Error- On a bad parameter type (JSONRPC2Error.INVALID_PARAMS).
-
getStringArray
public String[] getStringArray(String name) throws JSONRPC2Error
Retrieves the specified string array (maps from JSON array of strings) parameter.- Parameters:
name- The parameter name.- Returns:
- The parameter value as a string array.
- Throws:
JSONRPC2Error- On a missing parameter, bad type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getStringArray
public String[] getStringArray(String name, boolean allowNull) throws JSONRPC2Error
Retrieves the specified string array (maps from JSON array of strings) parameter.- Parameters:
name- The parameter name.allowNull- Iftrueallows anullvalue.- Returns:
- The parameter value as a string array.
- Throws:
JSONRPC2Error- On a missing parameter or bad type (JSONRPC2Error.INVALID_PARAMS).
-
getOptStringArray
public String[] getOptStringArray(String name, String[] defaultValue) throws JSONRPC2Error
Retrieves the specified optional string array (maps from JSON array of strings) parameter. If it doesn't exist the method will return the specified default value.- Parameters:
name- The parameter name.defaultValue- The default return value if the parameter doesn't exist. May benull.- Returns:
- The parameter value as a string array.
- Throws:
JSONRPC2Error- On a bad parameter type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getOptStringArray
public String[] getOptStringArray(String name, boolean allowNull, String[] defaultValue) throws JSONRPC2Error
Retrieves the specified optional string array (maps from JSON array of strings) parameter. If it doesn't exist the method will return the specified default value.- Parameters:
name- The parameter name.allowNull- Iftrueallows anullvalue.defaultValue- The default return value if the parameter doesn't exist. May benull.- Returns:
- The parameter value as a string array.
- Throws:
JSONRPC2Error- On a bad parameter type (JSONRPC2Error.INVALID_PARAMS).
-
getMap
public Map<String,Object> getMap(String name) throws JSONRPC2Error
Retrieves the specified map (maps from JSON object) parameter.- Parameters:
name- The parameter name.- Returns:
- The parameter value as a map.
- Throws:
JSONRPC2Error- On a missing parameter, bad type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getMap
public Map<String,Object> getMap(String name, boolean allowNull) throws JSONRPC2Error
Retrieves the specified map (maps from JSON object) parameter.- Parameters:
name- The parameter name.allowNull- Iftrueallows anullvalue.- Returns:
- The parameter value as a map.
- Throws:
JSONRPC2Error- On a missing parameter or bad type (JSONRPC2Error.INVALID_PARAMS).
-
getOptMap
public Map<String,Object> getOptMap(String name, Map<String,Object> defaultValue) throws JSONRPC2Error
Retrieves the specified optional map (maps from JSON object) parameter. If it doesn't exist the method will return the specified default value.- Parameters:
name- The parameter name.defaultValue- The default return value if the parameter doesn't exist. May benull.- Returns:
- The parameter value as a map.
- Throws:
JSONRPC2Error- On a bad parameter type ornullvalue (JSONRPC2Error.INVALID_PARAMS).
-
getOptMap
public Map<String,Object> getOptMap(String name, boolean allowNull, Map<String,Object> defaultValue) throws JSONRPC2Error
Retrieves the specified optional map (maps from JSON object) parameter. If it doesn't exist the method will return the specified default value.- Parameters:
name- The parameter name.allowNull- Iftrueallows anullvalue.defaultValue- The default return value if the parameter doesn't exist. May benull.- Returns:
- The parameter value as a map.
- Throws:
JSONRPC2Error- On a bad parameter type (JSONRPC2Error.INVALID_PARAMS).
-
-