#1 2024-04-23 10:48:11

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 238
Website

woDontStoreVoid and TObjectList

When streaming an object to Json, using

ObjectToJson(C, [woDontStoreDefault,woRawBlobAsBase64,woDontStoreVoid])

I ran into a problem, when a property is of type TObjectList.

Result: (Contained is published r/w property of type TObjectList:

// [woDontStoreDefault,woRawBlobAsBase64,woDontStoreVoid]
{"One":{"Name":"G"},"ID":42}

// [woDontStoreDefault,woRawBlobAsBase64]
{"One":{"Name":"G"},"ID":42,"Contained":[{"ClassName":"TOne","Name":"W"}]}

As soon as I omit woDontStoreVoid, it'll work just fine.

However, as I am trying to go through TInterfacedObjectFakeRaw.FakeCall -> TInterfacedObjectFake.FakeCallInternalProcess -> TInterfacedObjectFake.FakeCallGetJsonFromStack -> TInterfaceMethodArgument.AddJson (mocking in tests), Icannot control those parameters...

Regards,
Daniel

P.S.: A simple test project for this: https://filetransfer.io/data-package/C20KDkoc#link

Last edited by sakura (2024-04-23 11:11:35)

Offline

#2 2024-04-23 16:20:48

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,550
Website

Re: woDontStoreVoid and TObjectList

The documentation and source code states that plain TObjectList can be persisted into JSON, but not from JSON.
Because there is no way to know how to create the TObject instances when populating the list from JSON.

So TObjectList are not allowed as parameters of interface based services.
Use T*ObjArray or TCollections or other types of parameters, like plain RawJson or an array of records.

Offline

#3 2024-04-24 04:50:50

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 238
Website

Re: woDontStoreVoid and TObjectList

But it does work perfectly, when woDontStoreVoid is not part of the set. So, why do you write, that it is not possible? Even that part "from JSON". Have used it in other places before - without the woDontStoreVoid Attribute, never had a problem...

P.S.: I use it for places, where I cannot predetermine the type of object, that is going to be encountered. So a T*ObjArray wouldn't work, just a TCollections don't work, as all are tied to a single collection type.

Last edited by sakura (2024-04-24 04:52:25)

Offline

#4 2024-04-24 10:33:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,550
Website

Re: woDontStoreVoid and TObjectList

My bad, I didn't see that the "classname" property is used with the JSON content to store each item class.

Now I understand.
Please try:
https://github.com/synopse/mORMot2/commit/2889f04d

Offline

#5 2024-04-26 06:38:08

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 238
Website

Re: woDontStoreVoid and TObjectList

Thanks for reconsidering that change. It works perfectly.

Offline

Board footer

Powered by FluxBB