Can not use customized struct type
tfjiang opened this issue · comments
Hi, I define a customized struct type, and use it as return type of a function in services class.
struct my_info { QString name; };
I used Q_DECLARE_METATYPE and qRegisterMetaType to register the type.
However, I found that the function JsonRpcServer::createResponse failed because
return_value.type() == QVariant::UserType
is not well handled.
Could you fix this?
Hi,
I think what you suggest is on a higher level of abstraction than what the library aims for. Adding support for general (user) data types as return values and parameters would require some sort of serialization, and I don't think it's the responsibility of a JSON RPC library to provide this.
As a way to work around this, I suggest that you first convert your my_info
struct to a QVariantMap
:
auto m = QVariantMap{
{"name", "John Doe"},
{"age", 1337}
};
Then you can pass that QVariantMap
to one of the call
methods. For instance: auto result = rpc_client->call("person", m);
Of course, on the receiving end you would have to deserialize this and create a my_info
struct if needed.
If you need more advanced forms of serialization, you could use Base64-encoded strings.
Was this helpful?