As illustrated, the #storeOn: APIs aren't hardened serialization APIs. But if you're going to use them (instead one of the serialization projects that comes and goes every year or so), you can fight "clever" (which is what the 256 literal limit is, it's an optimization thing), with some "clever" of your own.
One trick, is to leverage that there is not a limit on what we might think of as "nested" literals.
a := #(1 2 3 4 5 6 7 8 9)
does not contain 10 literals. It just contains one, the array itself. It can have as many literals inside of it as it wants. So leveraging a little extra Dictionary
mojo, we can change your example to be:
d := Dictionary new.
(1 to: 257) do: [:each | d at: each put: each].
f := FileStream fileNamed: 'asdf.txt'.
pairs := d associations collect: [:kv | Array with: kv key with: kv value ].
pairs storeOn: f.
f reset.
d2 := Dictionary newFromPairs: (Array readFrom: f).
f close.
d2
Basically we're turning your dictionary into an Array of Arrays. So it's just one literal that you're going to store. And then we're using the handy newFromPairs:
which just happens to take ... drum roll ... an Array of Arrays.