You are not logged in.
Pages: 1
Thanks. It works!
Thanks! It works!
Oh... it seems to be easier then expected. I searched for hours and now the solution is so simple:
class function TMormotSerializer.Reader(const aValue: TObject; aFrom: PUTF8Char; var aValid: Boolean; aOptions: TJSONToObjectOptions): PUTF8Char;
var
Wrapper: IApiDataListObjectWrapper;
NewObject: TObject;
begin
Result := '';
if Assigned(aValue) then
begin
if aValue is TApiListBase then
begin
Wrapper := TApiListBase(AValue).Wrapper;
if Assigned(Wrapper) then
begin
TMormotSerializer.IgnoreChar(aFrom,'[');
while aFrom^ <> ']' do
begin
NewObject := Wrapper.CreateNew;
aFrom := JSONToObject(NewObject,aFrom,aValid);
if aValid then
Wrapper.AddObject(NewObject);
TMormotSerializer.IgnoreChar(aFrom,',');
end;
TMormotSerializer.IgnoreChar(aFrom,']');
end;
end;
end;
Result := aFrom;
For Explanation for my code:
I created some classes so i am able to use TList<T> for submitting Lists over my REST API. All i had to do is a custom-writer and a custom-reader (see above). Is is very flexible so i can define Lists what ever i want. I just have to make sure T is a kind of TObject.
If you (admin) are interested in. I can send you my units to show you what i have created.
Very good framework! I like it!
In the following JSON Example we can See "PVList" which is a TObject-Class (List) and i built a custom serializer to write this JSON. The Object of "PVList" Contains a List of other Objects.
Writing see serializer for writing the JSON was not a problem.
{
"result": {
"PVList": [{
"Bezeichnung": "Projekt 1"
},
{
"Bezeichnung": "Projekt 2"
},
{
"Bezeichnung": "Projekt 3"
},
{
"Bezeichnung": "Projekt 4"
}],
"Result": {
"Code": 0,
"Msg": "",
"Desc": ""
}
}
}
Now i try to develop the custom-reader. Currently i have no idea how to do this.
If my custom Reader Method is called:
class function TMormotSerializer.Reader(const aValue: TObject; aFrom: PUTF8Char; var aValid: Boolean; aOptions: TJSONToObjectOptions): PUTF8Char;
then "aFrom" points to this JSON:
[{
"Bezeichnung": "Projekt 1"
},
{
"Bezeichnung": "Projekt 2"
},
{
"Bezeichnung": "Projekt 3"
},
{
"Bezeichnung": "Projekt 4"
}],
"Result": {
"Code": 0,
"Msg": "",
"Desc": ""
}
}
}
I know exactly the Objects which are contained in "PVList". They are all the same objects.
So my question is:
How to parse the Array Element and create Objects from all the Items. I want to use JsonToObject() or something because i have a lot of similar Data. It is also possible that my "child-object" contains another "Object" (e.g. AnotherPVList) for which i have also a custom reader/writer.
As i mentioned: The writer works perfect and i get my desired JSON result! But how to develop the reader...
I think the ServiceDefine(...) method is unable to retrieve the Contract (_contract_) because it expects
this:
{
"result": {
"contract": "19AF8D194FF5E7E8"
}
}
but gets this:
{
"contract": "19AF8D194FF5E7E8"
}
Hey,
i want to work with "ResultAsJSONObjectWithoutResult" set on the Server side.
But if i try to Define a Service on the Client side like this:
HttpClient.ServiceDefine(ITest,sicShared);
I get a error because the Server Result is without "Result".
But as far as i know i can set "ResultAsJSONObjectWithoutResult" on ClientSide too. But this is first possible in the TServiceFactoryClient after i called ServiceDefine() :-(
It works if i use '*' for "expectedContract" --> but i don't want to.
It Works if i set ResultAsJSONObjectWithoutResult to false on the server side --> but i don't want to.
Can anyone help me to solve this problem?
Thanks,
Andreas
I have a Service defined which contains a simple function "GetGuid: TGUID".
This is the result:
{"Result":"BDB06275-9D94-46CF-B699-52FF890F9342",}
This JSON is invalid due to the additional comma.
Is this a Bug or is TGUID not supported properly?
Thanks,
Andreas
Hello,
i am new to mORMot and i really like the framework until now!
I am trying to develop a LicenseService running on a Server. I want the client to find the Server (Service) automatically without entering any IP-Adress.
Is there a possibility to send some kind of broadcast message to auto find the server? That would be great!
Thanks,
Andreas
Pages: 1