[JSONRPC-18] Add support for invocation of RPC method with object argument Created: 16/Mar/18 Updated: 23/Mar/18 Resolved: 23/Mar/18 |
|
| Status: | Resolved |
| Project: | jsonrpc |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Medium |
| Reporter: | Richard Kosegi | Assignee: | Richard Kosegi |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Messagelib currently support only scalar method argument types. It is possible to add support for them. Consider this POJO
public class SomePojo { private int field1; private String field2; // + getters/setters }
And this RPC method
public interface SomeRpc { Result callMe(SomePojo input); }
This RPC method can be invoked like this:
{"jsonrpc":"2.0","id":2,"method":"callMe","params":{"field1":10,"field2":"ABC"}}
Also it is possible to exploit GSON feature to add explicit mapping of parameter name to java field name. Let's say you have parameters named "field-1" and "field-2"
{"jsonrpc":"2.0","id":2,"method":"callMe","params":{"field-1":10,"field-2":"ABC"}}
Now you can specify json field name using annotation `SerializedName`:
import com.google.gson.annotations.SerializedName; public class SomePojo { @SerializedName("field-1") private int field1; @SerializedName("field-2") private String field2; // + getters/setters }
|