Class OracleOsonDecoder
- All Implemented Interfaces:
Decoder, AutoCloseable
OracleJsonDatum.shareBytes()).
The layout is a header with flags, a field name dictionary, and a tree segment of nodes whose containers
hold child field ids and offsets. Knowledge of that layout comes from the published open source
python-oracledb driver (Apache / UPL licensed, impl/base/oson.pyx), not from the Oracle JDBC driver,
whose license forbids decompilation. Field names are interned through an OracleOsonFieldNameCache so
a stream of documents with the same shape allocates no name strings after the first. Requires the AL32UTF8
database character set, which is what Oracle 23ai and later use for JSON.
Dates, timestamps, intervals, binary values and ids are reported as AbstractStreamDecoder.TokenType.OTHER, as the
OracleJdbcJsonParserDecoder reports them, so they are never read as numbers. Read as strings they use the
formats of the parser path: ISO-8601 dates and timestamps that always carry seconds, durations with a days part,
upper case hexadecimal for binary values and lower case for ids. VECTOR values are not supported and fail
when read.
- Since:
- 3.3.0
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractStreamDecoder
AbstractStreamDecoder.TokenType, AbstractStreamDecoder.ValueDecoder<R>Nested classes/interfaces inherited from class LimitingStream
LimitingStream.RemainingLimits -
Field Summary
Fields inherited from class LimitingStream
DEFAULT_LIMITS, DEFAULT_MAXIMUM_DEPTH -
Constructor Summary
ConstructorsConstructorDescriptionOracleOsonDecoder(byte[] data, int offset, int length, LimitingStream.RemainingLimits remainingLimits, CoercionPolicy coercionPolicy, OracleOsonFieldNameCache fieldNameCache) Creates a decoder positioned on the first token of a document. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringcoerceScalarToString(AbstractStreamDecoder.TokenType currentToken) Decode any non-null scalar value (number, string or boolean) to its string representation.createDeserializationException(String message, @Nullable Object invalidValue) Creates an exception for the given message.protected @Nullable AbstractStreamDecoder.TokenTypebyte[]Decodes an OSON binary value, or a string holding hexadecimal, or an array of bytes, as a byte array.Decodes an OSON date or timestamp, or an ISO-8601 string, as aLocalDateTime.Decodes an OSON timestamp with time zone, or an ISO-8601 string, as anOffsetDateTime.Decodes an OSON timestamp with time zone, or an ISO-8601 string, as aZonedDateTime.voidfinishStructure(boolean consumeLeftElements) protected NumberDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aNumbervalue.protected BigDecimalDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aBigDecimalvalue.protected BigIntegerDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aBigIntegervalue.protected booleanDecode the currentAbstractStreamDecoder.TokenType.BOOLEANvalue.protected StringGet the current object field name.protected doubleDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as a double value.protected longgetLong()Decode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as a long value.protected StringDecode the currentAbstractStreamDecoder.TokenType.STRINGvalue.protected booleanWhether the currentAbstractStreamDecoder.TokenType.NUMBERtoken has a fractional part.protected voidMove to the next token.protected voidIf we are at aAbstractStreamDecoder.TokenType.START_OBJECTorAbstractStreamDecoder.TokenType.START_ARRAY, skip to the matchingAbstractStreamDecoder.TokenType.END_OBJECTorAbstractStreamDecoder.TokenType.END_ARRAY.Methods inherited from class AbstractStreamDecoder
consumeLeftElements, decodeArbitrary, decodeArray, decodeArray0, decodeBigDecimal, decodeBigInteger, decodeBoolean, decodeBuffer, decodeByte, decodeChar, decodeCustom, decodeCustom, decodeDouble, decodeFloat, decodeInt, decodeKey, decodeLong, decodeNode, decodeNull, decodeNumber, decodeObject, decodeObject0, decodeShort, decodeString, getBestNumberNode, getBigDecimalFromNumber, getCoercionPolicy, getInteger, hasNextArrayValue, preDecodeValue, skipValue, unexpectedTokenMethods inherited from class LimitingStream
childLimits, decreaseDepth, increaseDepth, limitsFromConfiguration, ourLimitsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Decoder
close, decodeArray, decodeBigDecimalNullable, decodeBigIntegerNullable, decodeBinaryNullable, decodeBooleanNullable, decodeByteNullable, decodeCharNullable, decodeDoubleNullable, decodeFloatNullable, decodeIntNullable, decodeLongNullable, decodeNumber, decodeNumberNullable, decodeObject, decodeShortNullable, decodeStringNullable, finishStructure
-
Constructor Details
-
OracleOsonDecoder
public OracleOsonDecoder(byte[] data, int offset, int length, LimitingStream.RemainingLimits remainingLimits, CoercionPolicy coercionPolicy, OracleOsonFieldNameCache fieldNameCache) throws IOException Creates a decoder positioned on the first token of a document.- Parameters:
data- the OSON documentoffset- the offset of the document indatalength- the length of the documentremainingLimits- the nesting limitscoercionPolicy- the coercion policyfieldNameCache- the field name cache shared between documents- Throws:
IOException- if the bytes are not an OSON document this decoder understands
-
-
Method Details
-
finishStructure
- Specified by:
finishStructurein interfaceDecoder- Overrides:
finishStructurein classAbstractStreamDecoder- Parameters:
consumeLeftElements- True to consume left elements- Throws:
IOException- If an unrecoverable error occurs
-
currentToken
- Specified by:
currentTokenin classAbstractStreamDecoder- Returns:
- The current token.
-
nextToken
protected void nextToken()Description copied from class:AbstractStreamDecoderMove to the next token.- Specified by:
nextTokenin classAbstractStreamDecoder
-
getCurrentKey
Description copied from class:AbstractStreamDecoderGet the current object field name. Only called forAbstractStreamDecoder.TokenType.KEY.- Specified by:
getCurrentKeyin classAbstractStreamDecoder- Returns:
- The current field key
-
skipChildren
protected void skipChildren()Description copied from class:AbstractStreamDecoderIf we are at aAbstractStreamDecoder.TokenType.START_OBJECTorAbstractStreamDecoder.TokenType.START_ARRAY, skip to the matchingAbstractStreamDecoder.TokenType.END_OBJECTorAbstractStreamDecoder.TokenType.END_ARRAY. Else, do nothing.- Specified by:
skipChildrenin classAbstractStreamDecoder
-
coerceScalarToString
Description copied from class:AbstractStreamDecoderDecode any non-null scalar value (number, string or boolean) to its string representation.- Specified by:
coerceScalarToStringin classAbstractStreamDecoder- Parameters:
currentToken- The current token- Returns:
- The current value, coerced to a string
-
getString
Description copied from class:AbstractStreamDecoderDecode the currentAbstractStreamDecoder.TokenType.STRINGvalue. Called for no other token type.- Specified by:
getStringin classAbstractStreamDecoder- Returns:
- The String value
-
getBoolean
protected boolean getBoolean()Description copied from class:AbstractStreamDecoderDecode the currentAbstractStreamDecoder.TokenType.BOOLEANvalue. Called for no other token type.- Specified by:
getBooleanin classAbstractStreamDecoder- Returns:
- The boolean value
-
getLong
protected long getLong()Description copied from class:AbstractStreamDecoderDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as a long value. Called for no other token type.- Specified by:
getLongin classAbstractStreamDecoder- Returns:
- The number value
-
getDouble
protected double getDouble()Description copied from class:AbstractStreamDecoderDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as a double value. Called for no other token type.- Specified by:
getDoublein classAbstractStreamDecoder- Returns:
- The number value
-
getBigInteger
Description copied from class:AbstractStreamDecoderDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aBigIntegervalue. Called for no other token type.- Specified by:
getBigIntegerin classAbstractStreamDecoder- Returns:
- The number value
-
getBigDecimal
Description copied from class:AbstractStreamDecoderDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aBigDecimalvalue. Called for no other token type.- Specified by:
getBigDecimalin classAbstractStreamDecoder- Returns:
- The number value
-
getBestNumber
Description copied from class:AbstractStreamDecoderDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aNumbervalue. Called for no other token type.- Specified by:
getBestNumberin classAbstractStreamDecoder- Returns:
- The number value
-
isCurrentNumberFloat
protected boolean isCurrentNumberFloat()Description copied from class:AbstractStreamDecoderWhether the currentAbstractStreamDecoder.TokenType.NUMBERtoken has a fractional part. Only called when the configuration forbids reading a floating point number as an integer, so a decoder that never sees that configuration keeps working without implementing it.The default implementation materialises the number with
AbstractStreamDecoder.getBestNumber(). A decoder whose underlying parser consumes the value when it is read, as a forward only BSON reader does, must override this and answer from the token type instead.- Overrides:
isCurrentNumberFloatin classAbstractStreamDecoder- Returns:
trueif the current number is a floating point number
-
createDeserializationException
Description copied from interface:DecoderCreates an exception for the given message.- Parameters:
message- The message, nevernullinvalidValue- The invalid value. Can benull.- Returns:
- The exception, never
null
-
decodeBinary
Decodes an OSON binary value, or a string holding hexadecimal, or an array of bytes, as a byte array.- Specified by:
decodeBinaryin interfaceDecoder- Overrides:
decodeBinaryin classAbstractStreamDecoder- Returns:
- the bytes
- Throws:
IOException
-
decodeLocalDateTime
Decodes an OSON date or timestamp, or an ISO-8601 string, as aLocalDateTime.- Returns:
- the value
-
decodeOffsetDateTime
Decodes an OSON timestamp with time zone, or an ISO-8601 string, as anOffsetDateTime.- Returns:
- the value
-
decodeZonedDateTime
Decodes an OSON timestamp with time zone, or an ISO-8601 string, as aZonedDateTime.- Returns:
- the value
-