Le 30/07/2017 à 17:39, Stephane Ducasse a écrit :
Hi sven
I'm coding with my son a game collector application :) We want to save our collection with STON
So far we have
GameCollector asSTON >>
String streamContents: [ :s | STON put: self onStreamPretty: s ]
and we get
GameCollector { #items : OrderedCollection [ GameItem { #name : 'Final Fantasy X', #console : #PS2, #hasDocumentation : false, #hasBox : true, #finished : true, #condition : 'Good', #quotation : 10, #critics : 18, #comments : 'quite cool in fact' }, GameItem { #name : 'Final Fantasy XII', #console : '', #hasDocumentation : true, #hasBox : false, #finished : false, #condition : 'Good', #quotation : 10, #critics : 15, #comments : '' } ] }
And this is good. Now I wanted to use STON to save the items without the class structure
to get something like
OrderedCollection [ GameItem { #name : 'Final Fantasy X', #console : #PS2, #hasDocumentation : false, #hasBox : true, #finished : true, #condition : 'Good', #quotation : 10, #critics : 18, #comments : 'quite cool in fact' }, GameItem { #name : 'Final Fantasy XII', #console : '', #hasDocumentation : true, #hasBox : false, #finished : false, #condition : 'Good', #quotation : 10, #critics : 15, #comments : '' } ]
I coded as
GameCollector >> asSTON
^ String streamContents: [ :s | STON put: items onStreamPretty: s ]
and STON is not happy on reload.
I know that we are bending the rules. Is there a way to do simply what I want?
I could leave also with
GameItem { #name : 'Final Fantasy X', #console : #PS2, #hasDocumentation : false, #hasBox : true, #finished : true, #condition : 'Good', #quotation : 10, #critics : 18, #comments : 'quite cool in fact' }, GameItem { #name : 'Final Fantasy XII', #console : '', #hasDocumentation : true, #hasBox : false, #finished : false, #condition : 'Good', #quotation : 10, #critics : 15, #comments : '' }
Stef
Hi, Maybe you can just create a new GameCollector on the reading. "protocol: instance-creation" GameCollector class>>importFromFile: aFile ^ self new items: (STON fromString: aFile contents); yourself -- Cyril Ferlicot https://ferlicot.fr http://www.synectique.eu 2 rue Jacques Prévert 01, 59650 Villeneuve d'ascq France