Add array streaming helpers #115
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
An implementation of
#112 that introduces
beginArray/endArrayfor the streaming creation of arrays.In order to accomodate the need for intra-element plumbing, we add
begin/endmarker calls to thewriteValueimplementation which helps the writer keep track of each value being written and therefore allows it to inject the correct delimiters and indents.Here's an example of writing a
writeValueoverload that writes an array nested in an object:Similar to the existing
beginRecord/endRecordfields we addbeginArrayandendArray- we also take the opportunity to namebeginObjectaccording to its json-spec-derived name. The old name remains available.This change introduces a compile-time backwards-compatibility break for custom writers that try to access the stream directly: they now have to delimit their value writing with
w.streamElement(s): s.write ...wheresis the stream variable. The block template enforces begin/end markers on behalf of the writer.Further examples are available in the documentation.
With this change, we also deprecate workarounds like
fieldWrittenandendRecordFieldsince a regular replacement exists in the form of consistent begin/end pairs.