@Internal public abstract class AbstractStreamDecoder extends java.lang.Object implements Decoder
Decoder
s.Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractStreamDecoder.TokenType
The token type.
|
static interface |
AbstractStreamDecoder.ValueDecoder<R>
Decoder function for a single value.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractStreamDecoder(AbstractStreamDecoder parent)
Child constructor.
|
protected |
AbstractStreamDecoder(java.lang.Class<?> view)
Root constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
backFromChild(AbstractStreamDecoder child)
Called when the old child has finished processing and returns control of the stream to the parent.
|
protected abstract java.lang.String |
coerceScalarToString()
Decode any non-null scalar value (number, string or boolean) to its string representation.
|
protected abstract AbstractStreamDecoder |
createChildDecoder()
Create a new child decoder using
AbstractStreamDecoder(AbstractStreamDecoder) . |
protected abstract AbstractStreamDecoder.TokenType |
currentToken() |
java.lang.Object |
decodeArbitrary()
Decodes the current state into an arbitrary object.
|
Decoder |
decodeArray(io.micronaut.core.type.Argument<?> type)
Start decoding an array.
|
java.math.BigDecimal |
decodeBigDecimal()
Decodes a BigDecimal.
|
java.math.BigInteger |
decodeBigInteger()
Decodes a BigInteger.
|
boolean |
decodeBoolean()
Decodes a boolean.
|
Decoder |
decodeBuffer()
Buffer the whole subtree of this value and return it as a new
Decoder . |
byte |
decodeByte()
Decodes a byte.
|
char |
decodeChar()
Decodes a char.
|
protected <T> T |
decodeCustom(AbstractStreamDecoder.ValueDecoder<T> readFunction)
Decode a custom type.
|
protected <T> T |
decodeCustom(AbstractStreamDecoder.ValueDecoder<T> readFunction,
boolean callNext)
Decode a custom type.
|
double |
decodeDouble()
Decodes a double.
|
float |
decodeFloat()
Decodes a float.
|
int |
decodeInt()
Decodes a int.
|
java.lang.String |
decodeKey()
Decodes a key, if there are no more keys to decode returns
null . |
long |
decodeLong()
Decodes a long.
|
boolean |
decodeNull()
Attempt to decode a null value.
|
protected <T> T |
decodeNumber(AbstractStreamDecoder.ValueDecoder<T> fromNumberToken,
java.util.function.Function<java.lang.String,T> fromString,
T zero,
T one)
Decode a number type, applying all necessary coercions.
|
Decoder |
decodeObject(io.micronaut.core.type.Argument<?> type)
Decodes an object.
|
short |
decodeShort()
Decodes a short.
|
java.lang.String |
decodeString()
Decodes a string.
|
void |
finishStructure() |
protected abstract java.lang.Number |
getBestNumber()
Decode the current
AbstractStreamDecoder.TokenType.NUMBER value as a Number value. |
protected io.micronaut.json.tree.JsonNode |
getBestNumberNode()
Decode the current
AbstractStreamDecoder.TokenType.NUMBER value as a numeric JsonNode . |
protected abstract java.math.BigDecimal |
getBigDecimal()
Decode the current
AbstractStreamDecoder.TokenType.NUMBER value as a BigDecimal value. |
protected abstract java.math.BigInteger |
getBigInteger()
Decode the current
AbstractStreamDecoder.TokenType.NUMBER value as a BigInteger value. |
protected abstract boolean |
getBoolean()
Decode the current
AbstractStreamDecoder.TokenType.BOOLEAN value. |
protected abstract java.lang.String |
getCurrentKey()
Get the current object field name.
|
protected abstract double |
getDouble()
Decode the current
AbstractStreamDecoder.TokenType.NUMBER value as a double value. |
protected int |
getInteger()
Decode the current
AbstractStreamDecoder.TokenType.NUMBER value as a long value. |
protected abstract long |
getLong()
Decode the current
AbstractStreamDecoder.TokenType.NUMBER value as a long value. |
boolean |
hasNextArrayValue() |
protected abstract void |
nextToken()
Move to the next token.
|
protected abstract void |
skipChildren()
If we are at a
AbstractStreamDecoder.TokenType.START_OBJECT or AbstractStreamDecoder.TokenType.START_ARRAY , skip to the matching
AbstractStreamDecoder.TokenType.END_OBJECT or AbstractStreamDecoder.TokenType.END_ARRAY . |
void |
skipValue()
Skips the current value.
|
protected java.io.IOException |
unexpectedToken(AbstractStreamDecoder.TokenType expected) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close, createDeserializationException, decodeArray, decodeObject
protected AbstractStreamDecoder(@NonNull AbstractStreamDecoder parent)
parent
- The parent decoder.protected AbstractStreamDecoder(@NonNull java.lang.Class<?> view)
view
- The selected view class.@Nullable protected abstract AbstractStreamDecoder.TokenType currentToken()
protected abstract void nextToken() throws java.io.IOException
java.io.IOException
- if an unrecoverable error occursprotected java.io.IOException unexpectedToken(AbstractStreamDecoder.TokenType expected)
expected
- The token type that was expected in place of currentToken()
.public final void finishStructure() throws java.io.IOException
finishStructure
in interface Decoder
java.io.IOException
- If an unrecoverable error occursprotected void backFromChild(AbstractStreamDecoder child) throws java.io.IOException
AbstractStreamDecoder.TokenType.END_ARRAY
or AbstractStreamDecoder.TokenType.END_OBJECT
. However we currentToken()
may hold an outdated value until nextToken()
is called, which this method does.child
- The now-invalid child decoder.java.io.IOException
- if an unrecoverable error occurspublic final boolean hasNextArrayValue()
hasNextArrayValue
in interface Decoder
true
if another array value is available.protected abstract java.lang.String getCurrentKey() throws java.io.IOException
AbstractStreamDecoder.TokenType.KEY
.java.io.IOException
- if an unrecoverable error occurs@Nullable public final java.lang.String decodeKey() throws java.io.IOException
Decoder
null
.protected abstract AbstractStreamDecoder createChildDecoder()
AbstractStreamDecoder(AbstractStreamDecoder)
.@NonNull public final Decoder decodeArray(io.micronaut.core.type.Argument<?> type) throws java.io.IOException
Decoder
decodeArray
in interface Decoder
type
- The array typejava.io.IOException
- If an unrecoverable error occurs@NonNull public final Decoder decodeObject(io.micronaut.core.type.Argument<?> type) throws java.io.IOException
Decoder
decodeObject
in interface Decoder
type
- The type, never null
java.io.IOException
- If an unrecoverable error occursprotected abstract java.lang.String coerceScalarToString() throws java.io.IOException
java.io.IOException
- if an unrecoverable error occurs@NonNull public final java.lang.String decodeString() throws java.io.IOException
Decoder
decodeString
in interface Decoder
null
java.io.IOException
- If an unrecoverable error occursprotected abstract boolean getBoolean() throws java.io.IOException
AbstractStreamDecoder.TokenType.BOOLEAN
value. Called for no other token type.java.io.IOException
- if an unrecoverable error occurspublic final boolean decodeBoolean() throws java.io.IOException
Decoder
decodeBoolean
in interface Decoder
java.io.IOException
- If an unrecoverable error occurspublic final byte decodeByte() throws java.io.IOException
Decoder
decodeByte
in interface Decoder
java.io.IOException
- If an unrecoverable error occurspublic final short decodeShort() throws java.io.IOException
Decoder
decodeShort
in interface Decoder
java.io.IOException
- If an unrecoverable error occurspublic final char decodeChar() throws java.io.IOException
Decoder
decodeChar
in interface Decoder
java.io.IOException
- If an unrecoverable error occurspublic final int decodeInt() throws java.io.IOException
Decoder
public final long decodeLong() throws java.io.IOException
Decoder
decodeLong
in interface Decoder
java.io.IOException
- If an unrecoverable error occursprotected abstract long getLong() throws java.io.IOException
AbstractStreamDecoder.TokenType.NUMBER
value as a long value. Called for no other token type.java.io.IOException
- if an unrecoverable error occursprotected int getInteger() throws java.io.IOException
AbstractStreamDecoder.TokenType.NUMBER
value as a long value. Called for no other token type.java.io.IOException
- if an unrecoverable error occursprotected abstract double getDouble() throws java.io.IOException
AbstractStreamDecoder.TokenType.NUMBER
value as a double value. Called for no other token type.java.io.IOException
- if an unrecoverable error occursprotected abstract java.math.BigInteger getBigInteger() throws java.io.IOException
AbstractStreamDecoder.TokenType.NUMBER
value as a BigInteger
value. Called for no other token type.java.io.IOException
- if an unrecoverable error occursprotected abstract java.math.BigDecimal getBigDecimal() throws java.io.IOException
AbstractStreamDecoder.TokenType.NUMBER
value as a BigDecimal
value. Called for no other token type.java.io.IOException
- if an unrecoverable error occursprotected abstract java.lang.Number getBestNumber() throws java.io.IOException
AbstractStreamDecoder.TokenType.NUMBER
value as a Number
value. Called for no other token type.java.io.IOException
- if an unrecoverable error occursprotected io.micronaut.json.tree.JsonNode getBestNumberNode() throws java.io.IOException
AbstractStreamDecoder.TokenType.NUMBER
value as a numeric JsonNode
. Called for no other token type.
Default implementation tries to construct a node from getBestNumber()
.java.io.IOException
- if an unrecoverable error occurspublic final float decodeFloat() throws java.io.IOException
Decoder
decodeFloat
in interface Decoder
java.io.IOException
- If an unrecoverable error occurspublic final double decodeDouble() throws java.io.IOException
Decoder
decodeDouble
in interface Decoder
java.io.IOException
- If an unrecoverable error occurs@NonNull public final java.math.BigInteger decodeBigInteger() throws java.io.IOException
Decoder
decodeBigInteger
in interface Decoder
null
java.io.IOException
- If an unrecoverable error occurs@NonNull public final java.math.BigDecimal decodeBigDecimal() throws java.io.IOException
Decoder
decodeBigDecimal
in interface Decoder
null
java.io.IOException
- If an unrecoverable error occursprotected final <T> T decodeNumber(AbstractStreamDecoder.ValueDecoder<T> fromNumberToken, java.util.function.Function<java.lang.String,T> fromString, T zero, T one) throws java.io.IOException
T
- The number type.fromNumberToken
- Called if currentToken()
is a AbstractStreamDecoder.TokenType.NUMBER
.fromString
- Called for the textual value if currentToken()
is a AbstractStreamDecoder.TokenType.STRING
. Should throw NumberFormatException
on parse failure.zero
- The zero value.one
- The one value.java.io.IOException
- if an unrecoverable error occursprotected final <T> T decodeCustom(AbstractStreamDecoder.ValueDecoder<T> readFunction) throws java.io.IOException
T
- Value typereadFunction
- Function to call for reading the value. The AbstractStreamDecoder
parameter to the function will just be this
, but this allows subclasses to avoid capturing this
to avoid an allocation.java.io.IOException
- if an unrecoverable error occursprotected final <T> T decodeCustom(AbstractStreamDecoder.ValueDecoder<T> readFunction, boolean callNext) throws java.io.IOException
T
- Value typereadFunction
- Function to call for reading the value. The AbstractStreamDecoder
parameter to the function will just be this
, but this allows subclasses to avoid capturing this
to avoid an allocation.callNext
- Pass "true" if next token should be read after invocationjava.io.IOException
- if an unrecoverable error occurspublic final boolean decodeNull() throws java.io.IOException
Decoder
false
if this value is not null, and another method should be
used for decoding. Returns true
if this value was null, and the cursor has been advanced to the next
value.decodeNull
in interface Decoder
true
if the value was null
java.io.IOException
- If an unrecoverable error occurspublic Decoder decodeBuffer() throws java.io.IOException
Decoder
Decoder
. The returned Decoder
can
be used independently to this Decoder
. This means actual parsing of the subtree can be delayed.
The returned Decoder
should behave identically to this Decoder
. This means that for example
decoder.decodeDouble()
should be equivalent to decoder.decodeBuffer().decodeDouble()
.
decodeBuffer
in interface Decoder
java.io.IOException
- If an unrecoverable error occurs@Nullable public final java.lang.Object decodeArbitrary() throws java.io.IOException
Decoder
The following should be decoded by this method:
Map
List
decodeArbitrary
in interface Decoder
java.io.IOException
- If an unrecoverable error occursprotected abstract void skipChildren() throws java.io.IOException
AbstractStreamDecoder.TokenType.START_OBJECT
or AbstractStreamDecoder.TokenType.START_ARRAY
, skip to the matching
AbstractStreamDecoder.TokenType.END_OBJECT
or AbstractStreamDecoder.TokenType.END_ARRAY
. Else, do nothing.java.io.IOException
- if an unrecoverable error occurs