You are not logged in.
Pages: 1
Hi and sorry for the late reply.
thanks for pointing out TPolarionDto1573 = type TPolarionDto197 vs. TPolarionDto1573 = TPolarionDto197
personally I think your proposal for reducing the code is not worth it. But to be honest I dont understand size of .exe anyway.
I have a case study where I am parsing a json with mormot and put it into a virtual stringtree and I have a case study where I'm interfacing polarion and codebeamer with REST Api of cause also with mormot.
the json to stringtree is 6MB after stripping, the one with both REST Apis inside is 3.9 MB. - So I think the impact is not so big.
Nice to have: yes - but I think it would be rarely acutally used. I guess 95% are happy if it runs and won't go the extra step of defining some sort of config.
Besides I have to mention I need some rather small programs that need some bloatware they call "runtime engine" which has 650MB. So maybe I'm not too picky about file sizes ![]()
I have tested https://github.com/synopse/mORMot2/commit/e08e33ca3 with my current implementation.
I used GetCurrentUser, GetWorkItem, GetWorkItems, PatchWorkItem from the polarionrest.json of the first topic.
At least two commands had the issues mentioned before and are working with e08e33ca3. Great
! I used default settings (i.e. none of the optDto*Reduce*).
Just out of curiosity, why are you doing
TPolarionDto1573 = TPolarionDto197;
TPolarionDto1570 = packed record
_Type: TPolarionPolarionEnum54;
Attributes: TPolarionDto1571;
Relationships: TPolarionDto1573; //could use TPolarionDto197 directly here?
end;If the answer is "the dedup alogrithm is easier", does the compiler reduce this automagically ?
I can confirm it is the deduplication, which would also need to check against the actual types / followed records and not only the names (as far as I understand) of the current record.
This "Hotfix" removes the deduplication completely and "fixes" the issue shown in the previous post.
https://github.com/synopse/mORMot2/comm … a17d1cb762
I tried with https://github.com/synopse/mORMot2/commit/fe1370e77
it complies and except for the case mentioned before it seems to work.
one cannot answer the question if the code snippet is correct as one would need to see the content of TDtoApi2764
I draw a small and simplified uml which hopefully shows that the issue becomes apparent one step below the Data record.
https://github.com/D-H-R/various/blob/m … sponse.png
As I'm not sure if the numbers stay constant I also added the generated files: https://github.com/D-H-R/various/tree/m … _generator
I think there is an additional deduplication error.
"usersSingleGetResponse" in JSON has data.attributes.name. But in the DTO.pas file data "points" to a different attributes record, that has no "name" property (i guess it is pagesSingleGetResponse.data in json and not usersSingleGetResponse.data ) .
Hi and thanks for the great work.
I have the following Json REST Spec https://testdrive.polarion.com/polarion … nrest.json.
The mopenapi generator creates.
function TPolarionClient.GetAllDocuments(const Fields: TPolarionSparseFields;
PageSize: integer; PageNumber: integer; const Include: RawUtf8;
const Query: RawUtf8; const Sort: RawUtf8;
const Revision: RawUtf8): TPolarionDocumentsListGetResponse;
begin
fClient.Request('GET', '/all/documents', [], [
'page[size]', PageSize,
'page[number]', PageNumber,
'fields', Fields,
'include', Include,
'query', Query,
'sort', Sort,
'revision', Revision], [],
result, TypeInfo(TPolarionDocumentsListGetResponse));
end; The compiler says we are not allowed to put a (packed) record into an array constructor ![]()
polarion.client.pas(7835,15) Error: Wrong type "TPolarionSparseFields" in array constructor
Thanks so much for having a look into it.
This works as expected. Thanks for the work.
I think I found the next issue, but thats a story for the next Topic.
@ab: thanks for pointing that out. I Did not double check AI output enough, which set it on the wrong line. Shame on me, thanks to you ![]()
Should the DtoTypePrefix get a CLI parameter for the mopenapi tool or is it already and did I miss it too?
I found the issue but not a clean solution.
I need client option "jcoPayloadWithoutVoid". Which I set earlier in the created TCodeBeamerClient.create constructor. Of cause this one was overwritten by MOpenApi when regenerating it. Maybe thats why someone wrote "DO NOT MODIFY BY HAND" in the file ![]()
But I can not see a way how to do it without modifying xx.client.pas?
I did not found an option in MOpenApi to generate the flag.
I think I cannot hand it over from my Main Program because the codebeamer.client.pas hardcodes the options to:
constructor TCodeBeamerClient.Create(const aClient: IJsonClient);
begin
fClient := aClient;
fClient.Options := [jcoParseTolerant, jcoHttpErrorRaise];
fClient.UrlEncoder :=
[ueEncodeNames, ueSkipVoidString, ueSkipVoidValue, ueStarNameIsCsv];
end; Thanks for having a look into it. As it is a "side project" I need some days time until I can have a look back into it ![]()
I'm not 100% sure. But I think there is an issue. I wrote a small sample application that Gets and Puts a "Trackeritem". With the original mormot 2.4 release its working.
With the commit mentioned i added oa.DtoTypePrefix:='CodeBeamer'; to mopenapi tool.
generated Files look good.
I just exchanged the generated Files and added the "CodeBeamer" Prefix to the types, after that, the
GET REST command is working but for PUT command I now get: {"message": "JSON parse error: Class cannot be resolved by type: ","resourceUri":"/items3956"} during the runtime when I call the generated put function.
I know this looks like a "user issue" not using the REST Api correct, but as I did not really change s.th. in the code and it worked before...
Please let me know when it makes no sense to talk about it wihtout the actual source code. I'll check whats possible then. I dont know if they allow me to put the openapi spec public, as i needed to login to get it.
Thanks so much.
I ran into an Issue with the Swagger/OpenAPI Client Generator mopenapi from current Mormot 2.4 release.
It redefines typical FPC labels without hassitation...
In my case it redefined TLabel, wich is obviously a bad idea ![]()
There should be some mechanism / prefix to make sure typical fpc clases (label, edit etc.) are not overwritten.
I dont know if Im allowed to publish the full json, but this should be the critical part:
"Label": {
"type": "object",
"description": "Label that is used for entities like tags.",
"properties": {
"createdAt": {
"type": "string",
"format": "date-time",
"description": "The date when the entity was created"
},
"createdBy": {
"$ref": "#/components/schemas/UserReference"
},
"hidden": {
"type": "boolean",
"description": "Whether the label is hidden or not"
},
"id": {
"type": "integer",
"format": "int32",
"description": "Id of the entity",
"minimum": 0
},
"name": {
"type": "string",
"description": "Name of the entity"
},
"privateLabel": {
"type": "boolean",
"description": "Whether the label is private or not"
}
},
"readOnly": true
}Thanks and best regards
Dirk
Ok variant works, but ... its a variant ![]()
i.e. string:=variant works at compile time, but obviously crashes at runtime. Since I like strong typing, I'd prefer to get a compiler error.
Question: Can I have something that is like a dynarray but serializes as human readable correct json instead of blob?
(Note: TStrings gets JSON : "StrArr": "[\"1\",\"2\"]", but I need "StrArr": "["1","2"]")
Just Found the New Documentation. Great Work!
According to https://github.com/synopse/mORMot2/blob … pter-05.md I think it is intended behaviour because dynarrays are stored as blob.
I'll try (TDoc)Variant. My arrays are typically length<10 and I need to exchange them with different external services via JSON so I think it might be a good solution.
I want to have the TIntegerDynArray to be recognized as such, i.e. as JSON Array with ObjectToJson and in SQLite DB (for easier debugging).
What do I have to do? I think it might be related to RTTI in Lazarus 3.8 / FPC 3.2.2. If anyhow possible I'd like to stay with the current stable FPC release.
TParameter = class(TOrm)
private
fParameterID: integer;
fName: RawUtf8;
fValue: RawUtf8;
fIntArr: TIntegerDynArray;
published
property ParameterID: integer read fParameterID write fParameterID stored AS_UNIQUE;
property Name: RawUtf8 read fName write fName;
property Value: RawUtf8 read fValue write fValue;
property IntArr: TIntegerDynArray read fIntArr write fIntArr;
end;
Showmessage(Param.DynArray('IntArr').SaveToJson()); // returns [10,20,30,99].
ObjectToJson(TParameter); // is .. "IntArr": "AAADAAAAAAoAAAAUAAAAHgAAAA==" (same for entry in sqlite DB)Thanks a lot!
Somehow my brain doesn't like the square braces for this purpose. It seems to be linked to "access array / list element by position / memory offset" (I have to look at much C Code for embedded Systems). I think in this place the GetS() is exactly the same. Are there other places where it's worth to untie my brains knot ?
dict.PathDelim := '.';
Memo2.lines.add('short oneliner: ' + dict.GetS('measurementData.1.note')); Best regards
I have not yet all my use cases covered but the question how to access "note" from the inner ojbect is solved:
I used IDocList / Dict and it works like a breeze ![]()
dict := DocDict('{"text":"Some general Annot. Description","measurementData":[{"id":47,"note":"erster Teil","values":[1.1,1.2,1.3]},{"id":11,"note":"zweiter Teil","values":[2.1,2.2,2.3]}]}');
Memo2.lines.add('oneliner note' + dict.GetL('measurementData').GetD(1).GetS('note')); Thanks to both of you and especially flydev for this turnkey solution - superb!
Now I'm running into the next Issue I dont understand. Since JSON creation works so great I'm trying to read it back.
ObjLoadJson works fine if JSON and Object structure exactly match. However I need to tolerate if it is (slightly) modified by the user or if there is an update in the structure I need to read an old one or introduce new fields.
I wanted to do that with TDocVaraiant, but I cant Acces fields in the "measurementData" array of objects.
TDocVariantData(item).S['note'] fails in mormot.core.variants TDocVariantData.GetValueIndex because it expects cardinal(VType) = DocVariantVType, which is in my case (16396 = 271, obviously fail -> result-1)
procedure TForm1.Button9Click(Sender: TObject);
Var
doc: variant;
item: variant;
Begin
doc := _Json('{"text":"Some general Description","measurementData":[{"id":47,"note":"erster Teil","values":[1.1,1.2,1.3]},{"id":11,"note":"zweiter Teil","values":[2.1,2.2,2.3]}]}');
item := TDocVariantData(doc).A['measurementData'].Value[1];
Memo2.Lines.Clear;
Memo2.lines.add('Raw second element: ' + VariantToUtf8(TDocVariantData(doc).A['measurementData'].Value[1])); //returns {"id":11,"note":"zweiter Teil","values":[2.1,2.2,2.3]}
Memo2.lines.add('note: ' + TDocVariantData(item).S['note']); //fails "property note not found"
End; Thank you for you answer,
I'm lost in some rabbit hole
Every hour I'm working with it I'm more confused.
I'm using Lazarus 4.2 FPC 3.2.2
At least for now I put everything into records, and used TArray instead of IList. My best guess so far is documented at https://github.com/D-H-R/mormot_json/bl … /unit1.pas.
I know that RecordSaveJson is supposed to do base64 encoding, I wasn't able to get s.th. else running ![]()
As you might have expected I need a human readable format.
Can you please point out to me which classes (for data holding) and functions for the "toJson" I should use for a first approach.
Thank you so much.
Hello, everyone
I want to store and retrieve the data of an object with a list property in a json string. However I have a hard time getting this to work. I would appreciate some hints were I can find examples or if it is a good practice using a list instead of an array at all.
Thanks and best regards
My current failing example code:
TItem = Record
Name: String;
End;
TStorage = Class
Private
fPlace: RawUtf8;
fItems: IList < TItem > ;
Published
Property Place: RawUtf8 Read fPlace Write fPlace;
Property Items: IList < TItem > Read fItems Write fItems;
End;
[...]
Procedure TForm1.Button1Click(Sender: TObject);
Var
Storage: TStorage;
Item: TItem;
Begin
Storage := TStorage.Create;
Storage.Place := 'Ocean';
Storage.Items := Collections.NewPlainList < TItem > ;
Item.Name := 'Foo';
Storage.Items.Add(Item);
Item.Name := 'Bar';
Storage.Items.Add(Item);
Memo1.text := ObjectToJson(Storage, [woHumanReadable]); //does not print Items
End; Pages: 1