public class JsonParserImpl extends java.lang.Object implements JsonParser
JsonParser.Event
Constructor and Description |
---|
JsonParserImpl(java.io.InputStream in,
BufferPool bufferPool) |
JsonParserImpl(java.io.InputStream in,
java.nio.charset.Charset encoding,
BufferPool bufferPool) |
JsonParserImpl(java.io.Reader reader,
BufferPool bufferPool) |
Modifier and Type | Method and 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 . |
java.util.stream.Stream<JsonValue> |
getArrayStream()
Returns a stream of the
JsonArray elements. |
java.math.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 . |
java.util.stream.Stream<java.util.Map.Entry<java.lang.String,JsonValue>> |
getObjectStream()
Returns a stream of the
JsonObject 's
name/value pairs. |
java.lang.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. |
java.util.stream.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(java.io.Reader reader, BufferPool bufferPool)
public JsonParserImpl(java.io.InputStream in, BufferPool bufferPool)
public JsonParserImpl(java.io.InputStream in, java.nio.charset.Charset encoding, BufferPool bufferPool)
public java.lang.String getString()
JsonParser
String
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 JsonParser
JsonParser.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_NUMBER
public boolean isIntegralNumber()
JsonParser
BigDecimal
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 JsonParser
public int getInt()
JsonParser
new 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 JsonParser
BigDecimal.intValue()
public long getLong()
JsonParser
new 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 JsonParser
BigDecimal.longValue()
public java.math.BigDecimal getBigDecimal()
JsonParser
BigDecimal
. 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 JsonParser
BigDecimal
for a JSON numberpublic JsonArray getArray()
JsonParser
JsonArray
and advance the parser to the
the corresponding END_ARRAY
.getArray
in interface JsonParser
JsonArray
at the current parser positionpublic JsonObject getObject()
JsonParser
JsonObject
and advances the parser to the
corresponding END_OBJECT
.getObject
in interface JsonParser
JsonObject
at the current parser positionpublic JsonValue getValue()
JsonParser
JsonValue
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 JsonParser
JsonValue
at the current parser position.public java.util.stream.Stream<JsonValue> getArrayStream()
JsonParser
JsonArray
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, skipArray
can be used to
skip the unprocessed array elements.getArrayStream
in interface JsonParser
JsonArray
public java.util.stream.Stream<java.util.Map.Entry<java.lang.String,JsonValue>> getObjectStream()
JsonParser
JsonObject
'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, skipObject
can be
used to skip the unprocessed elements.getObjectStream
in interface JsonParser
JsonObject
public java.util.stream.Stream<JsonValue> getValueStream()
JsonParser
JsonValue
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 JsonParser
JsonValue
public void skipArray()
JsonParser
END_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 JsonParser
public void skipObject()
JsonParser
END_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 JsonParser
public JsonLocation getLocation()
JsonParser
getLocation
in interface JsonParser
public JsonLocation getLastCharLocation()
public boolean hasNext()
JsonParser
true
if there are more parsing states. This method returns
false
if the parser reaches the end of the JSON text.hasNext
in interface JsonParser
true
if there are more parsing states.public JsonParser.Event next()
JsonParser
next
in interface JsonParser
public void close()
JsonParser
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface JsonParser
Copyright © 2012-2018, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.
Comments to : jsonp-dev@eclipse.org