Skip to content

Add functionality for the omission of unused optional parameters in a JSON-RPC request#314

Draft
liamgilligan wants to merge 1 commit intoConsensusJ:masterfrom
liamgilligan:jrpc-param-handling
Draft

Add functionality for the omission of unused optional parameters in a JSON-RPC request#314
liamgilligan wants to merge 1 commit intoConsensusJ:masterfrom
liamgilligan:jrpc-param-handling

Conversation

@liamgilligan
Copy link
Contributor

@liamgilligan liamgilligan commented Feb 10, 2026

JSON-RPC allows for unused optional parameters to be omitted from the params member of a Request object. params is represented by an Array. It only requires that required parameters are present and that the present parameters are in the order the server expects. For more details, see https://www.jsonrpc.org/specification#parameter_structures

This PR adds the server-side functionality to handle these omitted parameters when they are given by-position, as specified in the JSON-RPC spec.

JSON-RPC allows for unused optional parameters to be omitted from the `params` member of a Request object when `params` is represented by an Array. It only requires that required parameters are present and that the present parameters are in the order the server expects. For more details, see https://www.jsonrpc.org/specification\#parameter_structures
Copy link
Member

@msgilligan msgilligan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but I have three minor requests.

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using wildcard imports. Your IDE may be doing this automatically -- check your IDE settings.

When doing PR reviews it's important to see exactly which classes are imported and which imports have been added or removed.

return paramsFromNet;
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, but I would put the helper method below callMethod in the source file.

CompletableFuture<RSLT> future;
final Method mh = getMethod(methodName);
if (mh != null) {
params = addNullParams(mh.getParameterCount(), params);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The params variable should not be mutated here. With rare exceptions we try to treat all local and parameter variables as "effectively final" (but without explicitly adding the final keyword) IDEs generally mark mutated variables with an underline or similar indication, so you can be made aware of when this happening.

So please create a new local variable here (maybe completeParams?) and pass it to the mh.invoke().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants