Class JsonParserImpl
java.lang.Object
org.glassfish.json.JsonParserImpl
- All Implemented Interfaces:
Closeable, AutoCloseable, JsonParser
JSON parser implementation. NoneContext, ArrayContext, ObjectContext is used
to go to next parser state.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classprivate classprivate final classprivate final classprivate static final classNested classes/interfaces inherited from interface JsonParser
JsonParser.Event -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BufferPoolprivate JsonParserImpl.Contextprivate JsonParser.Eventprivate final JsonParserImpl.Stackprivate final JsonTokenizer -
Constructor Summary
ConstructorsConstructorDescriptionJsonParserImpl(InputStream in, Charset encoding, BufferPool bufferPool) JsonParserImpl(InputStream in, BufferPool bufferPool) JsonParserImpl(Reader reader, BufferPool bufferPool) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this parser and frees any resources associated with the parser.getArray()Returns aJsonArrayand advance the parser to the the correspondingEND_ARRAY.private JsonArraygetArray(JsonArrayBuilder builder) Returns a stream of theJsonArrayelements.Returns a JSON number as aBigDecimal.intgetInt()Returns a JSON number as an integer.Return the location that corresponds to the parser's current state in the JSON input source.longgetLong()Returns a JSON number as a long.Returns aJsonObjectand advances the parser to the correspondingEND_OBJECT.private JsonObjectgetObject(JsonObjectBuilder builder) Returns a stream of theJsonObject's name/value pairs.Returns aStringfor the name in a name/value pair, for a string value or a number value.getValue()Returns aJsonValueat the current parser position.Returns a stream ofJsonValuefrom a sequence of JSON values.booleanhasNext()Returnstrueif there are more parsing states.(package private) boolean(package private) booleanbooleanReturns true if the JSON number at the current parser state is a integral number.next()Returns the event for the next parsing state.private JsonParsingExceptionparsingException(JsonTokenizer.JsonToken token, String expectedTokens) voidAdvance the parser toEND_ARRAY.voidAdvance the parser toEND_OBJECT.
-
Field Details
-
bufferPool
-
currentContext
-
currentEvent
-
stack
-
tokenizer
-
-
Constructor Details
-
JsonParserImpl
-
JsonParserImpl
-
JsonParserImpl
-
-
Method Details
-
getString
Description copied from interface:JsonParserReturns aStringfor 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 isJsonParser.Event.KEY_NAME,JsonParser.Event.VALUE_STRING, orJsonParser.Event.VALUE_NUMBER.- Specified by:
getStringin interfaceJsonParser- Returns:
- a name when the parser state is
JsonParser.Event.KEY_NAMEa string value when the parser state isJsonParser.Event.VALUE_STRINGa number value when the parser state isJsonParser.Event.VALUE_NUMBER
-
isIntegralNumber
public boolean isIntegralNumber()Description copied from interface:JsonParserReturns true if the JSON number at the current parser state is a integral number. ABigDecimalmay be used to store the value internally and this method semantics are defined using itsscale(). 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(); }- Specified by:
isIntegralNumberin interfaceJsonParser- Returns:
- true if this number is a integral number, otherwise false
-
getInt
public int getInt()Description copied from interface:JsonParserReturns a JSON number as an integer. The returned value is equal tonew 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 isJsonParser.Event.VALUE_NUMBER.- Specified by:
getIntin interfaceJsonParser- Returns:
- an integer for a JSON number
- See Also:
-
isDefinitelyInt
boolean isDefinitelyInt() -
isDefinitelyLong
boolean isDefinitelyLong() -
getLong
public long getLong()Description copied from interface:JsonParserReturns a JSON number as a long. The returned value is equal tonew 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 isJsonParser.Event.VALUE_NUMBER.- Specified by:
getLongin interfaceJsonParser- Returns:
- a long for a JSON number
- See Also:
-
getBigDecimal
Description copied from interface:JsonParserReturns a JSON number as aBigDecimal. TheBigDecimalis created usingnew BigDecimal(getString()). This method should only called when the parser state isJsonParser.Event.VALUE_NUMBER.- Specified by:
getBigDecimalin interfaceJsonParser- Returns:
- a
BigDecimalfor a JSON number
-
getArray
Description copied from interface:JsonParserReturns aJsonArrayand advance the parser to the the correspondingEND_ARRAY.- Specified by:
getArrayin interfaceJsonParser- Returns:
- the
JsonArrayat the current parser position
-
getObject
Description copied from interface:JsonParserReturns aJsonObjectand advances the parser to the correspondingEND_OBJECT.- Specified by:
getObjectin interfaceJsonParser- Returns:
- the
JsonObjectat the current parser position
-
getValue
Description copied from interface:JsonParserReturns aJsonValueat the current parser position. If the parser state isSTART_ARRAY, the behavior is the same asJsonParser.getArray(). If the parser state isSTART_OBJECT, the behavior is the same asJsonParser.getObject(). For all other cases, if applicable, the JSON value is read and returned.- Specified by:
getValuein interfaceJsonParser- Returns:
- the
JsonValueat the current parser position.
-
getArrayStream
Description copied from interface:JsonParserReturns a stream of theJsonArrayelements. The parser state must beSTART_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.- Specified by:
getArrayStreamin interfaceJsonParser- Returns:
- a stream of elements of the
JsonArray
-
getObjectStream
Description copied from interface:JsonParserReturns a stream of theJsonObject's name/value pairs. The parser state must beSTART_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.- Specified by:
getObjectStreamin interfaceJsonParser- Returns:
- a stream of name/value pairs of the
JsonObject
-
getValueStream
Description copied from interface:JsonParserReturns a stream ofJsonValuefrom a sequence of JSON values. The values are read lazily, on an as-needed basis, as needed by the stream operations.- Specified by:
getValueStreamin interfaceJsonParser- Returns:
- a Stream of
JsonValue
-
skipArray
public void skipArray()Description copied from interface:JsonParserAdvance the parser toEND_ARRAY. If the parser is in array context, i.e. it has previously encountered aSTART_ARRAYwithout encountering the correspondingEND_ARRAY, the parser is advanced to the correspondingEND_ARRAY. If the parser is not in any array context, nothing happens.- Specified by:
skipArrayin interfaceJsonParser
-
skipObject
public void skipObject()Description copied from interface:JsonParserAdvance the parser toEND_OBJECT. If the parser is in object context, i.e. it has previously encountered aSTART_OBJECTwithout encountering the correspondingEND_OBJECT, the parser is advanced to the correspondingEND_OBJECT. If the parser is not in any object context, nothing happens.- Specified by:
skipObjectin interfaceJsonParser
-
getArray
-
getObject
-
getLocation
Description copied from interface:JsonParserReturn the location that corresponds to the parser's current state in the JSON input source. The location information is only valid in the current parser state (or until the parser is advanced to a next state).- Specified by:
getLocationin interfaceJsonParser- Returns:
- a non-null location corresponding to the current parser state in JSON input source
-
getLastCharLocation
-
hasNext
public boolean hasNext()Description copied from interface:JsonParserReturnstrueif there are more parsing states. This method returnsfalseif the parser reaches the end of the JSON text.- Specified by:
hasNextin interfaceJsonParser- Returns:
trueif there are more parsing states.
-
next
Description copied from interface:JsonParserReturns the event for the next parsing state.- Specified by:
nextin interfaceJsonParser- Returns:
- the event for the next parsing state
-
close
public void close()Description copied from interface:JsonParserCloses this parser and frees any resources associated with the parser. This method closes the underlying input source.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceJsonParser
-
parsingException
-