public class JsonParserImpl extends Object implements JsonParser
JsonParser.Event
Constructor and Description |
---|
JsonParserImpl(InputStream in,
BufferPool bufferPool) |
JsonParserImpl(InputStream in,
Charset encoding,
BufferPool bufferPool) |
JsonParserImpl(Reader reader,
BufferPool bufferPool) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this parser and frees any resources associated with the
parser.
|
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.
|
String |
getString()
Returns a
String for the name in a name/value pair,
for a string value or a number value. |
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.
|
public JsonParserImpl(Reader reader, BufferPool bufferPool)
public JsonParserImpl(InputStream in, BufferPool bufferPool)
public JsonParserImpl(InputStream in, Charset encoding, BufferPool bufferPool)
public 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 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 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 Closeable
close
in interface AutoCloseable
close
in interface JsonParser
Copyright © 2022 Oracle. All rights reserved.