Closeable, AutoCloseable, JsonParserpublic class JsonParserImpl extends Object implements JsonParser
JsonParser.Event| Constructor | Description |
|---|---|
JsonParserImpl(InputStream in,
Charset encoding,
BufferPool bufferPool) |
|
JsonParserImpl(InputStream in,
BufferPool bufferPool) |
|
JsonParserImpl(Reader reader,
BufferPool bufferPool) |
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
Closes this parser and frees any resources associated with the
parser.
|
JsonArray |
getArray() |
Returns a
JsonArray and advance the parser to the
the corresponding END_ARRAY. |
Stream<JsonValue> |
getArrayStream() |
Returns a stream of the
JsonArray elements. |
BigDecimal |
getBigDecimal() |
Returns a JSON number as a
BigDecimal. |
int |
getInt() |
Returns a JSON number as an integer.
|
JsonLocation |
getLastCharLocation() |
|
JsonLocation |
getLocation() |
Return the location that corresponds to the parser's current state in
the JSON input source.
|
long |
getLong() |
Returns a JSON number as a long.
|
JsonObject |
getObject() |
Returns a
JsonObject and advances the parser to the
corresponding END_OBJECT. |
Stream<Map.Entry<String,JsonValue>> |
getObjectStream() |
Returns a stream of the
JsonObject's
name/value pairs. |
String |
getString() |
Returns a
String for the name in a name/value pair,
for a string value or a number value. |
JsonValue |
getValue() |
Returns a
JsonValue at the current parser position. |
Stream<JsonValue> |
getValueStream() |
Returns a stream of
JsonValue from a sequence of
JSON values. |
boolean |
hasNext() |
Returns
true if there are more parsing states. |
boolean |
isIntegralNumber() |
Returns true if the JSON number at the current parser state is a
integral number.
|
JsonParser.Event |
next() |
Returns the event for the next parsing state.
|
void |
skipArray() |
Advance the parser to
END_ARRAY. |
void |
skipObject() |
Advance the parser to
END_OBJECT. |
public JsonParserImpl(Reader reader, BufferPool bufferPool)
public JsonParserImpl(InputStream in, BufferPool bufferPool)
public JsonParserImpl(InputStream in, Charset encoding, BufferPool bufferPool)
public String getString()
JsonParserString for the name in a name/value pair,
for a string value or a number value. This method should only be called
when the parser state is JsonParser.Event.KEY_NAME, JsonParser.Event.VALUE_STRING,
or JsonParser.Event.VALUE_NUMBER.getString in interface JsonParserJsonParser.Event.KEY_NAME
a string value when the parser state is JsonParser.Event.VALUE_STRING
a number value when the parser state is JsonParser.Event.VALUE_NUMBERpublic boolean isIntegralNumber()
JsonParserBigDecimal may be used to store the value
internally and this method semantics are defined using its
scale(). If the scale is zero, then it is considered integral
type. This integral type information can be used to invoke an
appropriate accessor method to obtain a numeric value as in the
following example:
JsonParser parser = ...
if (parser.isIntegralNumber()) {
parser.getInt(); // or other methods to get integral value
} else {
parser.getBigDecimal();
}
isIntegralNumber in interface JsonParserpublic int getInt()
JsonParsernew BigDecimal(getString()).intValue(). Note that
this conversion can lose information about the overall magnitude
and precision of the number value as well as return a result with
the opposite sign. This method should only be called when the parser
state is JsonParser.Event.VALUE_NUMBER.getInt in interface JsonParserBigDecimal.intValue()public long getLong()
JsonParsernew BigDecimal(getString()).longValue(). Note that this
conversion can lose information about the overall magnitude and
precision of the number value as well as return a result with
the opposite sign. This method is only called when the parser state is
JsonParser.Event.VALUE_NUMBER.getLong in interface JsonParserBigDecimal.longValue()public BigDecimal getBigDecimal()
JsonParserBigDecimal. The BigDecimal
is created using new BigDecimal(getString()). This
method should only called when the parser state is
JsonParser.Event.VALUE_NUMBER.getBigDecimal in interface JsonParserBigDecimal for a JSON numberpublic JsonArray getArray()
JsonParserJsonArray and advance the parser to the
the corresponding END_ARRAY.getArray in interface JsonParserJsonArray at the current parser positionpublic JsonObject getObject()
JsonParserJsonObject and advances the parser to the
corresponding END_OBJECT.getObject in interface JsonParserJsonObject at the current parser positionpublic JsonValue getValue()
JsonParserJsonValue at the current parser position.
If the parser state is START_ARRAY, the behavior is
the same as JsonParser.getArray(). If the parser state is
START_OBJECT, the behavior is the same as
JsonParser.getObject(). For all other cases, if applicable, the JSON value is
read and returned.getValue in interface JsonParserJsonValue at the current parser position.public Stream<JsonValue> getArrayStream()
JsonParserJsonArray elements.
The parser state must be START_ARRAY.
The elements are read lazily, on an as-needed basis, as
required by the stream operations.
If the stream operations do not consume
all of the array elements, JsonParser.skipArray() can be used to
skip the unprocessed array elements.getArrayStream in interface JsonParserJsonArraypublic Stream<Map.Entry<String,JsonValue>> getObjectStream()
JsonParserJsonObject's
name/value pairs. The parser state must be START_OBJECT.
The name/value pairs are read lazily, on an as-needed basis, as
required by the stream operations.
If the stream operations do not consume
all of the object's name/value pairs, JsonParser.skipObject() can be
used to skip the unprocessed elements.getObjectStream in interface JsonParserJsonObjectpublic Stream<JsonValue> getValueStream()
JsonParserJsonValue from a sequence of
JSON values. The values are read lazily, on an as-needed basis,
as needed by the stream operations.getValueStream in interface JsonParserJsonValuepublic void skipArray()
JsonParserEND_ARRAY.
If the parser is in array context, i.e. it has previously
encountered a START_ARRAY without encountering the
corresponding END_ARRAY, the parser is advanced to
the corresponding END_ARRAY.
If the parser is not in any array context, nothing happens.skipArray in interface JsonParserpublic void skipObject()
JsonParserEND_OBJECT.
If the parser is in object context, i.e. it has previously
encountered a START_OBJECT without encountering the
corresponding END_OBJECT, the parser is advanced to
the corresponding END_OBJECT.
If the parser is not in any object context, nothing happens.skipObject in interface JsonParserpublic JsonLocation getLocation()
JsonParsergetLocation in interface JsonParserpublic JsonLocation getLastCharLocation()
public boolean hasNext()
JsonParsertrue if there are more parsing states. This method returns
false if the parser reaches the end of the JSON text.hasNext in interface JsonParsertrue if there are more parsing states.public JsonParser.Event next()
JsonParsernext in interface JsonParserpublic void close()
JsonParserclose in interface AutoCloseableclose in interface Closeableclose in interface JsonParserCopyright © 2018 Oracle. All rights reserved.