Call XData Services from Client that aren't written in Delphi

Hello,
I'm trying to write a XData Server that must expose some API that can be consumed by various Client in different languages.
I want to use JSON as standard, so I taught it could be sufficient send to the service a JSON formatted string as Parameter (for example: {"Value": {"Username":"gs","Password":"gs"}}) that I could deserialize server-side, but I noticed that there is some issues doing like this: using the Delphi Built-in REST Debugger, if I use this JSON as body, I get a TJsonTypeConverter.EConvertFromJsonError with message 'Cannot read JSON property of type "string", invalid value.'; if I invoke the service as usual using XDataClient with the same parameter, the JSON that is sent it's something like this:
{"Value":"{"Value": {"Username":"gs","Password":"gs"}}"}.
Using the parameter attribute [FromBody] I've been able to send correctly the JSON on the request, but the response is like this (it could be an array of objects):
{
"value": "[{"Id":1,"Username":"gs","User_Password":"gs","Active":true,"Company":"Galeno Sistemi srl","First_Name":{},"Surname":{},"Company_Address":{},"City":{},"Country":{},"Email":{},"Phone":{},"Mw_Sn":{},"Mw_Exp_Date":{},"Is_Active":{},"Deleted":{},"Registration_Date":{},"E2E_TP_USER":{"Id":1,"Description":"Cliente","Tp_Code":"CLI"},"E2E_GROUPList":[],"E2E_AFFILIATIONList":[]}]"
}

Is there any way to send to and receive from server a standard JSON that can be used or it's necessary to add backslash every time there is a double quote char when I send to server a JSON string param and delete it when the client receive the response?

Thanks in advance

You don't need (and shouldn't) receive the JSON as a string. If you want your clients (Delphi or another) to send an arbitrary JSON value, you can simple declare the parameter as TJSONValue type.
If you declare the parameter as string using [FromBody], the parameter is understood as a JSON property inside a jSON object.

If you still have questions, please provide more details about how your service is declared and how you are sending/receiving it. You mentioned backslash but I don't see any in your message.

Hello,
thanks for the advice, it worked correctly.

In the previous JSON sample, the JSON was written like this
{
"value": "[{\"Id\":1\,"Username\":\"gs\",\"User_Password\":\"gs\",\"Active\":true,\"Company\":\"Galeno Sistemi srl\",\"First_Name\":{},\"Surname\":{},\"Company_Address\":{},\"City\":{},\"Country\":{},\"Email\":{},\"Phone\":{},\"Mw_Sn\":{},\"Mw_Exp_Date\":{},\"Is_Active\":{},\"Deleted\":{},\"Registration_Date\":{},\"E2E_TP_USER\":{\"Id\":1,\"Description\":\"Cliente\",\"Tp_Code\":\"CLI\"},\"E2E_GROUPList\":[],\"E2E_AFFILIATIONList\":[]}]"
}
it seems a wrong parsing of double quote char.

Thanks again and have a nice day.

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.