A generalized JSON processor.
The processor traverses JSON-like data as provided by a JsonReader.
It dispatches to individual process
methods for each
kind of JSON value, but doesn't process the value
by default.
These methods can be overridden in subclasses to do something useful.
For example, the JsonSinkProcessor defaults to forwarding
each kind of JSON data to a JsonSink.
The processor is similar to a JsonSink
in that there are methods for each kind of JSON data,
but instead of passing the JSON values to the individual add
methods,
the process
methods of the processsor takes a reader
which is ready to provide the value.
The process-method can either read the value, skip it, or even read the source using JsonReader.expectAnyValueSource and handle it itself.
Each process-method takes a key
which is non-null when the
value is a JSON-object value. This allows the processor
to easily skip entire entries, perhaps even based on the
key name.
An example implementation of processNum could be:
void processNum(JsonReader reader, String? key) {
if (key != null && key.startsWith("x-")) {
// Ignore key and value.
reader.skipAnyValue();
} else {
// Add key and value to a JsonSink.
if (key != null) sink.addKey(key);
sink.addNumber(reader.expectNum());
}
}
- Implementers
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
endArray(
String? key) → void - Called when an array has no more elements.
-
endObject(
String? key) → void - Called after all key/value pairs of the current object are processed.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
processArray(
Reader reader, String? key) → bool - Called when the reader encounters a JSON array.
-
processBool(
Reader reader, String? key) → void - Called when the next value is a boolean value.
-
processNull(
Reader reader, String? key) → void -
Called when the next value is a
null
value. -
processNum(
Reader reader, String? key) → void - Called when the next value is a number value.
-
processObject(
Reader reader, String? key) → bool - Called when the reader encounters the start of a JSON object.
-
processObjectEntry(
Reader reader) → void - Called for each JSON object entry.
-
processString(
Reader reader, String? key) → void - Called when the next value is a string value.
-
processUnknown(
Reader reader, String? key) → void - Invoked for a reader which has no value or an unrecognized value.
-
processValue(
Reader reader, [String? key]) → void - Process a JSON-value.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited