jnan77 / jsonrpc4j

Automatically exported from code.google.com/p/jsonrpc4j
0 stars 0 forks source link

Add possibility to have optional parameters #10

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
It would be great if there was a way to have optional parameters in the remote 
interface.

For example, define the remote interface something like this:

public interface MyRemoteInterface {
    String someMethod(

         @JsonRpcParamOptional 
         @JsonRpcParamName("optionalParam")
         String optionalParam, 

         @JsonRpcParamName("mandatoryParam") 
         String mandatoryParam
    );
};

Where it would be allowed to both pass:
"params": {
    "optionalParam": "test1",
    "mandatoryParam": "test2"
}

And
"params": {
    "mandatoryParam": "test2"
}

In the second case the optionalParam parameter would be set to null when 
issuing the call to the implementation class.

Original issue reported on code.google.com by erl...@isaksson.info on 5 Jan 2012 at 5:30

GoogleCodeExporter commented 8 years ago
This will be taken into consideration for a future release of the library.  In 
the mean time, with careful planning you can take advantage of the 
allowExtraParams functionality of the JsonRpcServer and put your optional 
parameters at the end of your method signature. I do realise that there are 
issues with this "solution" however.  Another option is taking a single object 
as a parameter to the method ie:

String someMethod(Whatever argument);

where Whatever is:

class Whatever {
    String optionalParam;
    String mandatoryParam;
}

or a variation of the above.

I do understand that neither of these workarounds are perfect - they are merely 
workarounds.

Original comment by brian.di...@gmail.com on 8 Feb 2012 at 8:14

GoogleCodeExporter commented 8 years ago
This has been address in 0.20-SNAPSHOT via the "allowLessParmaters" setting.  
Please test it.

Original comment by brian.di...@gmail.com on 9 Feb 2012 at 2:24

GoogleCodeExporter commented 8 years ago

Original comment by brian.di...@gmail.com on 25 May 2012 at 2:51

GoogleCodeExporter commented 8 years ago

Original comment by brian.di...@gmail.com on 26 May 2012 at 2:44