Class JsonFraming
pekko.util.ByteString objects.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThrown if upstream completes with a partial object in the buffer.static class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Flow<ByteString,ByteString, NotUsed> objectScanner(int maximumObjectLength) Returns a Flow that implements a "brace counting" based framing operator for emitting JSON objects.
-
Constructor Details
-
JsonFraming
public JsonFraming()
-
-
Method Details
-
objectScanner
Returns a Flow that implements a "brace counting" based framing operator for emitting JSON objects. It scans the incoming data stream for JSON objects and returns chunks of ByteStrings containing those objects.This operator only frames JSON objects; it is not a general-purpose JSON parser and does not validate the object contents. A top-level JSON array is supported only when all its elements are objects. Other top-level JSON values, such as strings, numbers, booleans, or
null, are not supported. JSON Lines or NDJSON input is supported when every record is an object. A leading UTF-8 byte-order mark (BOM) must be removed before framing.Typical examples of data that one may want to frame using this operator include:
**Very large arrays**:
[{"id": 1}, {"id": 2}, [...], {"id": 999}]**Multiple concatenated JSON objects** (with, or without commas between them):
{"id": 1}, {"id": 2}, [...], {"id": 999}The framing works independently of formatting, i.e. it will still emit JSON objects even if two elements are separated by multiple newlines or other whitespace characters. And of course is insensitive (and does not impact the emitting frame) to the JSON object's internal formatting.
For streaming nested JSON structures, see Apache Pekko Connectors JSON support.
If the stream completes while mid-object, the stage will fail with a
JsonFraming.PartialObjectException.- Parameters:
maximumObjectLength- The maximum length of allowed frames while decoding. If the maximum length is exceeded this Flow will fail the stream.
-