class JsonStructureParser extends java.lang.Object implements JsonParser
JsonParser implementation on top of JsonArray/JsonObject| Modifier and Type | Class and Description |
|---|---|
private static class |
JsonStructureParser.ArrayScope |
private static class |
JsonStructureParser.ObjectScope |
private static class |
JsonStructureParser.Scope |
JsonParser.Event| Modifier and Type | Field and Description |
|---|---|
private JsonStructureParser.Scope |
current |
private java.util.Deque<JsonStructureParser.Scope> |
scopeStack |
private JsonParser.Event |
state |
| Constructor and Description |
|---|
JsonStructureParser(JsonArray array) |
JsonStructureParser(JsonObject object) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this parser and frees any resources associated with the
parser.
|
java.math.BigDecimal |
getBigDecimal()
Returns a JSON number as a
BigDecimal. |
int |
getInt()
Returns a JSON number as an integer.
|
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.
|
private static JsonParser.Event |
getState(JsonValue value) |
java.lang.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.
|
private void |
transition() |
private JsonStructureParser.Scope current
private JsonParser.Event state
private final java.util.Deque<JsonStructureParser.Scope> scopeStack
JsonStructureParser(JsonArray array)
JsonStructureParser(JsonObject object)
public java.lang.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 java.math.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 JsonLocation getLocation()
JsonParsergetLocation in interface JsonParserpublic 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 JsonParserprivate void transition()
public void close()
JsonParserclose in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in interface JsonParserprivate static JsonParser.Event getState(JsonValue value)