The JADE 2022 release meets tomorrow’s business demands.
I'm encountering quirky behaviour using 'sendMsgWithParams' with mixed types between the source variable and destination argument. An example to re-create the issue:
Sending a variable as Binary type
Receiving a argument as String
destinationMethod(inputArgument : String);
begin
write inputArgument;
end;
sendingMethod();
begin
sendMsgWithParams("destinationMethod", "text".Binary);
end;
Run the above the 'write' statement is: 74 65 78 74 >text <
To get the expected result, I need to change the destinationMethod line to: write inputArgument.String;
The above can be re-created with other combinations of types like numbers. To work around this I have cast the arguments again in the receiving methods, which kinda looks weird seeing arguments cast as String with the suffix ".String". I'm having to make this change to more and more methods, so now more code is looking weirder.
The other option is to create a sendMsgWithParams overload that does a type-check and re-casts all the arguments before invoking the method... this solution seems a bit overkill.
Any chance I have missed something and there is a better way to work around this? The long story is I'm de-serializing json payloads and pushing the data to methods. I know the expected type of the argument when I figure out the destination method (which depends on the payload), just trying to find a cleaner way to code this.
May I request the 'Parameter' class have a new method: getType()
Thanks
I appreciate that I need to ensure the parameter type matches the destination method.
I can retrieve the 'ParameterColl' from the method with the along with the 'Parameter' objects. Is there a way I can get the type for each parameter? If so I can re-cast my variable and send it's new type to 'sendMsgWithParams'.
I am hoping there is a way more strongly-typed than reading the first line of the source code and deciphering the parameters that way.
This may be more appropriate for the Jade Forums, as it's not a suggestion for an improvement in Jade. It is the developers responsibility to ensure you are passing the correct types into sendMsgWithParams to avoid unexpected behaviour, as per the following comment in the documentation:
"If the number or type of the actual parameters passed to a method or condition by a parameter list does not correspond exactly to the formal parameter list declaration, an exception or an unpredictable result can occur, as the compiler is unable to perform any type checking on the values that are passed to a parameter list."