String testMethod(@JsonRpcParam("param1") String param1); }
private void collectArgumentsBasedOnName(Method method, Set<String> paramNames, List<JsonRpcParam> allNames, ObjectNode paramNodes) { Class<?>[] types = method.getParameterTypes(); int numParameters = types.length; for (int i = 0; i < numParameters; i++) { JsonRpcParam param = allNames.get(i); if (param != null && paramNames.contains(param.value())) { if (types[i].isArray() && method.isVarArgs() && numParameters == 1) { collectVarargsFromNode(paramNodes.get(param.value())); } else { addArgument(paramNodes.get(param.value())); } } else { addArgument(NullNode.getInstance()); } } }
String methodWithoutRequiredParam(@JsonRpcParam("param1") String stringParam1, @JsonRpcParam(value = "param2") String stringParam2); }
/** * Checks method for @JsonRpcParam annotations and returns named parameters. * * @param method the method * @param arguments the arguments * @return named parameters or empty if no annotations found * @throws IllegalArgumentException if some parameters are annotated and others not */ private static Map<String, Object> getNamedParameters(Method method, Object[] arguments) { Map<String, Object> namedParams = new LinkedHashMap<>(); Annotation[][] paramAnnotations = method.getParameterAnnotations(); for (int i = 0; i < paramAnnotations.length; i++) { Annotation[] ann = paramAnnotations[i]; for (Annotation an : ann) { if (JsonRpcParam.class.isInstance(an)) { JsonRpcParam jAnn = (JsonRpcParam) an; namedParams.put(jAnn.value(), arguments[i]); break; } } } if (arguments != null && arguments.length > 0 && namedParams.size() > 0 && namedParams.size() != arguments.length) { throw new IllegalArgumentException("JsonRpcParam annotations were not found for all parameters on method " + method.getName()); } return namedParams; }
String testMethod(@JsonRpcParam("param1") String param1);
public ParameterCount(Set<String> paramNames, ObjectNode paramNodes, List<Class<?>> parameterTypes, Method method) { this.allNames = getAnnotatedParameterNames(method); this.method = method; int typeCount = 0; int nameCount = 0; int at = 0; for (JsonRpcParam name : this.allNames) { if (missingAnnotation(name)) { continue; } String paramName = name.value(); boolean hasParamName = paramNames.contains(paramName); if (hasParamName) { nameCount += 1; } if (hasParamName && isMatchingType(paramNodes.get(paramName), parameterTypes.get(at))) { typeCount += 1; } at += 1; } this.typeCount = typeCount; this.nameCount = nameCount; }
String overloadedMethod(@JsonRpcParam("param1") int intParam1);
String overloadedMethod(@JsonRpcParam("param1") int intParam1, @JsonRpcParam("param2") int intParam2);
String overloadedMethod(@JsonRpcParam("param1") String stringParam1, @JsonRpcParam("param2") String stringParam2);
String overloadedMethod(@JsonRpcParam("param1") String stringParam1);
void someNamedParams(@JsonRpcParam("one") String one, int two);
void allNamedParams(@JsonRpcParam("one") String one, @JsonRpcParam("two") int two);
@JsonRpcMethod("mixedObjectPrimitiveVarargMethodWithJsonRpcParam") String mixedObjectPrimitiveVarargMethodWithJsonRpcParam(@JsonRpcParam("object") Object test, @JsonRpcParam("ints") int... ints); }
@JsonRpcMethod("mixedObjectStringVarargMethodWithJsonRpcParam") String mixedObjectStringVarargMethodWithJsonRpcParam(@JsonRpcParam("object") Object test, @JsonRpcParam("strings") String... strings);
@JsonRpcMethod(value = "allNamedParamsPassParamsArray", paramsPassMode = JsonRpcParamsPassMode.ARRAY) void allNamedParamsPassParamsArray(@JsonRpcParam("one") String one, @JsonRpcParam("two") int two);
@JsonRpcMethod(value = "allNamedParamsPassParamsAuto", paramsPassMode = JsonRpcParamsPassMode.AUTO) void allNamedParamsPassParamsAuto(@JsonRpcParam("one") String one, @JsonRpcParam("two") int two);
@JsonRpcMethod(value = "allNamedParamsPassParamsObject", paramsPassMode = JsonRpcParamsPassMode.OBJECT) void allNamedParamsPassParamsObject(@JsonRpcParam("one") String one, @JsonRpcParam("two") int two);
@JsonRpcMethod(value = "someNamedParamsPassParamsArray", paramsPassMode = JsonRpcParamsPassMode.ARRAY) void someNamedParamsPassParamsArray(@JsonRpcParam("one") String one, int two);
@JsonRpcMethod("varargStringMethodWithJsonRpcParam") String varargStringMethodWithJsonRpcParam(@JsonRpcParam("strings") String... strings);
@JsonRpcMethod("varargPrimitiveMethodWithJsonRpcParam") String varargPrimitiveMethodWithJsonRpcParam(@JsonRpcParam("ints") int... ints);