From the unit test, this allows you to do as follows:
self
assert: ((NeoJSONReader on: 'null' readStream)
mapInstVarsFor: Point;
for: Point do: [ :mapping | mapping allowNil ];
nextAs: Point)
equals: nil.
self
assert: ((NeoJSONReader on: '[ { "x" : 1, "y" : 2 }, null, { "x" : 3, "y" : -1 } ]' readStream)
mapInstVarsFor: Point;
for: Point do: [ :mapping | mapping allowNil ];
for: #ArrayOfPoints customDo: [ :mapping | mapping listOfElementSchema: Point ];
nextAs: #ArrayOfPoints)
equals: { 1 @ 2. nil. 3 @ -1 }.
I decided to make this a per mapping option, not a per reader option.
Maybe there should be an ensureNotNil option too, which sets allowNil to false?
This allows for changing it back to the default mode when reusing the same reader.
I tried making this a per _property mapping_ option, but it became a bit of a hack so I stopped doing that.
You could try experimenting with Custom mappings, they allow arbitrary conversions, but I doubt if you could really prevent intermediate structure creation. But maybe I just don't see it right, and it is possible after all.
One could perhaps use adoptInstance:, based on some conditions (e.g. ���if the json contains this combination of keys���, ���if the type field has the value ���commit������).
But on the other hand this solution would make NeoJSON less simple, and the simplicity of the library is a very nice property. It would be stupid to throw that property away for a solution that doesn't even cover all of the cases.
If the returned JSON is highly dynamic and variable, I would just use dynamic mode and then in a second pass convert the maps/lists to domain objects myself. Or someone should write a generic maps/lists to domain model objects mapper (independent of JSON).
Yes this might be the best solution in this case.
Best wishes for 2016 :),
Skip