Package oracle.sql.json
Interface OracleJsonParser
- 
- All Superinterfaces:
- AutoCloseable,- Closeable
 
 public interface OracleJsonParser extends Closeable Reads a JSON type value from an input source as a stream of events. Call Example:next()to advance the parser to the next event in the stream and use accessor methods such asgetString()andgetInt()to access the data associated with the current event.import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; import oracle.sql.json.OracleJsonFactory; import oracle.sql.json.OracleJsonGenerator; import oracle.sql.json.OracleJsonParser; import oracle.sql.json.OracleJsonParser.Event; public class JsonParserExample { public static void main(String[] args) { OracleJsonFactory factory = new OracleJsonFactory(); // Generate binary JSON value {"hello":"world","arr":[1,2]} ByteArrayOutputStream out = new ByteArrayOutputStream(); OracleJsonGenerator generator = factory.createJsonBinaryGenerator(out); generator.writeStartObject(); generator.write("hello", "world"); generator.writeStartArray("arr"); generator.write(1); generator.write(2); generator.writeEnd(); generator.writeEnd(); generator.close(); byte[] binaryJson = out.toByteArray(); OracleJsonParser parser = factory.createJsonBinaryParser(ByteBuffer.wrap(binaryJson)); while (parser.hasNext()) { Event e = parser.next(); System.out.println(e); switch (e) { case START_OBJECT: case START_ARRAY: case END_ARRAY: case END_OBJECT: break; // do nothing case KEY_NAME: System.out.println(parser.getString()); break; case VALUE_STRING: System.out.println(parser.getString()); break; case VALUE_DECIMAL: System.out.println(parser.getBigDecimal()); break; default: break; } } parser.close(); } }Running this example prints: START_OBJECT KEY_NAME hello VALUE_STRING world KEY_NAME arr START_ARRAY VALUE_DECIMAL 1 VALUE_DECIMAL 2 END_ARRAY END_OBJECT 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Interface Description static classOracleJsonParser.Event
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()Closes the parser and closes any resources associated with it.OracleJsonArraygetArray()Returns the current array value and advances the current state to the correspondingEND_ARRAYevent.BigDecimalgetBigDecimal()Returns the current value as a decimal value.BigIntegergetBigInteger()Returns a value equal togetBigDecimal().toBigInteger().byte[]getBytes()Return the current binary value as a byte arrayvoidgetBytes(OutputStream out)Return the current binary value to the specified output stream.doublegetDouble()Returns current event as a double.java.time.DurationgetDuration()Return the current interval as a duration.floatgetFloat()Returns current event as a float.intgetInt()Returns a value equal to getBigDecimal().intValue().java.time.LocalDateTimegetLocalDateTime()Returns the current date or timestamp as aLocalDateTimevalue.longgetLong()Returns a value equal to getBigDecimal().longValue().OracleJsonObjectgetObject()Returns the current object and advances the current state to the correspondingEND_OBJECTevent.\java.time.OffsetDateTimegetOffsetDateTime()Returns the current timestamptz as anOffsetDateTimevalue.java.time.PeriodgetPeriod()Return the current interval as a period.StringgetString()Gets a string for the current event.OracleJsonValuegetValue()Return the value at the current parser event.booleanhasNext()Returns true if there are additional parsing events.booleanisIntegralNumber()Returns true if the current event is an integral number.OracleJsonParser.Eventnext()Return the next parsing event.voidskipArray()Skips the current array value, advancing the parser to the correspondingEND_ARRAY.voidskipObject()Skips the current array value, advancing the parser to the correspondingEND_OBJECT.<T> Twrap(Class<T> wrapper)Returns a JSON-P wrapper around this value.
 
- 
- 
- 
Method Detail- 
hasNextboolean hasNext() Returns true if there are additional parsing events.- Returns:
- true if there are more parsing events.
- Throws:
- OracleJsonException- if an io error occurs
- OracleJsonParsingException- if the JSON is invalid
 
 - 
nextOracleJsonParser.Event next() Return the next parsing event.- Returns:
- the next event
- Throws:
- OracleJsonException- if an io error occurs
- OracleJsonParsingException- if the JSON is invalid
- NoSuchElementException- if there are no more parsing events
 
 - 
getStringString getString() Gets a string for the current event. If the current event isKEY_NAMEthis method returns the key value.- Returns:
- the string value
- Throws:
- IllegalStateException- if the current event is not- VALUE_STRING,- KEY_NAME,- VALUE_DECIMAL,- VALUE_DOUBLE,- VALUE_FLOAT,- VALUE_BINARY,- VALUE_INTERVALDS,- VALUE_INTERVALYM,- VALUE_DATE,- VALUE_TIMESTAMP, or- VALUE_TIMESTAMPTZ
 
 - 
isIntegralNumberboolean isIntegralNumber() Returns true if the current event is an integral number. Specifically, this method returns true whengetBigDecimal().scale()is equal to 0.- Returns:
- true if the current number is an integral number.
- Throws:
- IllegalStateException- if the current event is not- VALUE_DECIMAL,- VALUE_DOUBLE, or- VALUE_FLOAT
 
 - 
getIntint getInt() Returns a value equal to getBigDecimal().intValue().- Returns:
- the int value
- Throws:
- IllegalStateException- if the current event is not- VALUE_DECIMAL,- VALUE_DOUBLE, or- VALUE_FLOAT
 
 - 
getLonglong getLong() Returns a value equal to getBigDecimal().longValue().- Returns:
- the long value
- Throws:
- IllegalStateException- if the current event is not- VALUE_DECIMAL,- VALUE_DOUBLE, or- VALUE_FLOAT
 
 - 
getDoubledouble getDouble() Returns current event as a double.- Returns:
- the double
- Throws:
- IllegalStateException- if the current event is not- VALUE_DECIMAL,- VALUE_DOUBLE, or- VALUE_FLOAT
 
 - 
getFloatfloat getFloat() Returns current event as a float.- Returns:
- the float
- Throws:
- IllegalStateException- if the current event is not- VALUE_DECIMAL,- VALUE_DOUBLE, or- VALUE_FLOAT
 
 - 
getBigIntegerBigInteger getBigInteger() Returns a value equal togetBigDecimal().toBigInteger().- Returns:
- the integer
- Throws:
- IllegalStateException- if the current event is not- VALUE_DECIMAL,- VALUE_DOUBLE, or- VALUE_FLOAT
 
 - 
getBigDecimalBigDecimal getBigDecimal() Returns the current value as a decimal value.- Returns:
- the decimal
- Throws:
- IllegalStateException- if the current event is not- VALUE_DECIMAL,- VALUE_DOUBLE, or- VALUE_FLOAT
 
 - 
getOffsetDateTimejava.time.OffsetDateTime getOffsetDateTime() Returns the current timestamptz as anOffsetDateTimevalue.- Returns:
- the offset date time
- Throws:
- IllegalStateException- if the current event is not- VALUE_TIMESTAMPTZ
 
 - 
getLocalDateTimejava.time.LocalDateTime getLocalDateTime() Returns the current date or timestamp as aLocalDateTimevalue.- Returns:
- the local date time
- Throws:
- IllegalStateException- if the current event is not- VALUE_DATEor- VALUE_TIMESTAMP
 
 - 
getPeriodjava.time.Period getPeriod() Return the current interval as a period.- Returns:
- the period
- Throws:
- IllegalStateException- if the current event is not- VALUE_INTERVALYM
 
 - 
getDurationjava.time.Duration getDuration() Return the current interval as a duration.- Returns:
- the duration
- Throws:
- IllegalStateException- if the current event is not- VALUE_INTERVALDS
 
 - 
getBytesbyte[] getBytes() Return the current binary value as a byte array- Returns:
- the byte array
- Throws:
- IllegalStateException- if the current event is not- VALUE_BINARY.
 
 - 
getBytesvoid getBytes(OutputStream out) Return the current binary value to the specified output stream.- Throws:
- IllegalStateException- if the current event is not- VALUE_BINARY.
 
 - 
getValueOracleJsonValue getValue() Return the value at the current parser event. If the current event isSTART_ARRAY, the result is the same as call togetArray(). If the current event isSTART_OBJECT, the result is the same as a call to . In other cases, the current value is read and returned.- Returns:
- the value
- Throws:
- IllegalStateException- if the current event is- END_OBJECTor- END_ARRAY
 
 - 
getArrayOracleJsonArray getArray() Returns the current array value and advances the current state to the correspondingEND_ARRAYevent.- Returns:
- the array value
- Throws:
- IllegalStateException- if the current event is not- START_ARRAY
 
 - 
getObjectOracleJsonObject getObject() Returns the current object and advances the current state to the correspondingEND_OBJECTevent.\- Returns:
- the object value
- Throws:
- IllegalStateException- if the current event is not- START_OBJECT
 
 - 
skipArrayvoid skipArray() Skips the current array value, advancing the parser to the correspondingEND_ARRAY.- Throws:
- IllegalStateException- if the current event is not- START_OBJECT
 
 - 
skipObjectvoid skipObject() Skips the current array value, advancing the parser to the correspondingEND_OBJECT.- Throws:
- IllegalStateException- if the current event is not- START_OBJECT
 
 - 
wrap<T> T wrap(Class<T> wrapper) Returns a JSON-P wrapper around this value. For example:import jakarta.json.stream.JsonParser; ... OracleJsonParser oraParser = ...; JsonParser parser = oraParser.wrap(JsonParser.class);The returned object is a logical view of this generator. Any changes to the state of this parser are observed by the returned wrapper object. - Parameters:
- wrapper- the interface to view this object as. Must be assignable to- javax.json.stream.JsonParser(deprecated) or- jakarta.json.stream.JsonParser
- Returns:
 
 - 
closevoid close() Closes the parser and closes any resources associated with it.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Throws:
- OracleJsonException- if an i/o error occurs
 
 
- 
 
-