On 17 May 2017, at 14:15, Cyril Ferlicot D. <cyril.ferlicot@gmail.com> wrote:
On 17/05/2017 13:46, Sven Van Caekenberghe wrote:
On 17 May 2017, at 12:44, Sven Van Caekenberghe <sven@stfx.eu> wrote:
Hi Cyril,
This can be done quite easily in STON, I will make you a small example and add it to the unit tests.
=== Name: STON-Tests-SvenVanCaekenberghe.79 Author: SvenVanCaekenberghe Time: 17 May 2017, 1:43:03.944446 pm UUID: fb472e87-180c-0d00-b559-fec60aee7555 Ancestors: STON-Tests-SvenVanCaekenberghe.78
Add STONWriteReadTests>>#testKnownObjects as an example of how to serialize only an ID and resolve that ID upon materialization
Add STONTestKnownObject with custom #stonOn: and class side #fromSton: ===
You basically (over)write 2 methods, instance side
"protocol: ston-core" stonOn: stonWriter "We only write out our id"
stonWriter writeObject: self listSingleton: self id asString
and class side
"protocol: ston-core" fromSton: stonReader ^ self fromId: stonReader parseListSingleton
The #fromId: methods retrieves an existing instance.
HTH,
Sven
Hi Sven,
I do not want to keep all the KnowObjects in the memory. One of the goal is to export from an image and to load from another.
The following does not work:
| obj string| obj := STONTestKnownObject new description: 'something else'; yourself. string := STON toStringPretty: obj. STONTestKnownObject resetKnownObjects. self assert: (STON fromString: string) description = 'something else'
Of course that does not work, it is your job to do something similar that fits your use case. You certainly do not have to cache everything. On the other had, if you only serialise part of an object, or just one reference (id, url, name) like in the example, how will you recreate the rest, unless you have access to it ? And that is what your version of #fromId: should do. I can't understand how your 'to export from an image and to load from another' can possibly work, unless there is some other way of sharing the data. But I probably don't understand you, I known nothing about Moose models.
What is the simple may to customize only one or two variable(s)?
-- Cyril Ferlicot https://ferlicot.fr
http://www.synectique.eu 2 rue Jacques Prévert 01, 59650 Villeneuve d'ascq France