NeoJSON: parsing mapped nil fields
Hi all, When parsing with NeoJSON, Iâm experiencing some problems. If I parse a JSON representation using NeoJSONReader>>next (i.e. not according to a schema), it parses nil fields just fine. But when I explicitly set a value schema, it wonât parse it in the case it is nil (or ânullâ in JSON). Is there a way to let it return nil in the case the parser encounters ânullâ, and otherwise serialize it as a value schema (e.g. a Point class). Taking the example from the paper (https://github.com/svenvc/docs/blob/master/neo/neo-json-paper.md <https://github.com/svenvc/docs/blob/master/neo/neo-json-paper.md>): (NeoJSONReader on: ânull' readStream) mapInstVarsFor: Point; nextAs: Point. Is there a way to adapt the above snippet so that it evaluates to ânilâ instead of resulting in an error? I ask because I am parsing an API response which sometimes contains a ânullâ field, and sometimes a JSON object for that field. Thanks.
Hi,
On 22 Dec 2015, at 17:40, Skip Lentz <skip.lentz@inria.fr> wrote:
Hi all,
When parsing with NeoJSON, Iâm experiencing some problems.
If I parse a JSON representation using NeoJSONReader>>next (i.e. not according to a schema), it parses nil fields just fine. But when I explicitly set a value schema, it wonât parse it in the case it is nil (or ânullâ in JSON). Is there a way to let it return nil in the case the parser encounters ânullâ, and otherwise serialize it as a value schema (e.g. a Point class).
Taking the example from the paper (https://github.com/svenvc/docs/blob/master/neo/neo-json-paper.md): (NeoJSONReader on: ânull' readStream) mapInstVarsFor: Point; nextAs: Point.
Is there a way to adapt the above snippet so that it evaluates to ânilâ instead of resulting in an error? I ask because I am parsing an API response which sometimes contains a ânullâ field, and sometimes a JSON object for that field.
Thanks.
NeoJSON does have a bit of a split personality. When using #next it parses whatever is there and returns it as either primitives, a map or a list, nested to any depth. When you use mappings and #nextAs: it tries to map a static type structure on what is coming in. As such it is not really prepared for dynamic surprises like objects being replaced by null. Do also note that the typing info is totally absent from the JSON itself, unlike STON for example. NeoJSON also tries (and succeeds) in maintaining a stream based parser that does not generate intermediate structures except your own domain models. But your request does make sense and I will think about it. It might be possible. It has been a while that I really thought about the implementation. Sven
participants (2)
-
Skip Lentz -
Sven Van Caekenberghe