Interface JsonIterator
public interface JsonIterator
An iterable JSON structure. Abstraction based on Jsoniter.
- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceElement/entry iterator.static enumJSON value types. -
Method Summary
Modifier and TypeMethodDescriptionasMap()Turns the full iterator into a map of objects.booleancontainsKey(String key) Does the givenkeyexist in the underlying JSON structure.entries()Returns all entries.get(int index) Returns the i-th element in the underlying array structure.Returns the value of the givenkey.Returns any key, in particular ifsize()is1, the first/only key.intsize()Returns the size of the underlying structure.byte[]slice(byte[] data, JsonIterator iter) Slicesdataso that the nested part ofiterremains.Turns this iterator to a big decimal value.Turns this iterator to a big integer value.booleanTurns this iterator to a boolean value.doubleTurns this iterator to a double value.floatTurns this iterator to a float value.intTurns this iterator to an int value.longTurns this iterator to a long value.Turns this iterator to a string value.Returns the value type.
-
Method Details
-
valueType
JsonIterator.ValueType valueType()Returns the value type.- Returns:
- the value type
-
containsKey
Does the givenkeyexist in the underlying JSON structure.- Parameters:
key- the key- Returns:
trueif the key exist,falseelse
-
get
Returns the value of the givenkey. Use eitheriterator-based accessor name-based access.- Parameters:
key- the key- Returns:
- the value, may be null for none
-
slice
Slicesdataso that the nested part ofiterremains.- Parameters:
data- the dataiter- the iterator to slice for- Returns:
- the sliced part of
data - Throws:
IOException- if slicing fails
-
size
int size()Returns the size of the underlying structure.- Returns:
- the size
-
get
Returns the i-th element in the underlying array structure.- Parameters:
index- the 0-based index- Returns:
- the element
- Throws:
IndexOutOfBoundsException- if not in rage, seesize()
-
entries
JsonIterator.EntryIterator entries()Returns all entries. Use either iterator-based access orname-based access.- Returns:
- all entries
-
getAnyKey
String getAnyKey()Returns any key, in particular ifsize()is1, the first/only key. Works only on objects.- Returns:
- any key, may be null
-
toStringValue
Turns this iterator to a string value.- Returns:
- the string value
- Throws:
IOException- if the actual value is not a string
-
toDoubleValue
Turns this iterator to a double value.- Returns:
- the double value
- Throws:
IOException- if the actual value is not a double
-
toFloatValue
Turns this iterator to a float value.- Returns:
- the float value
- Throws:
IOException- if the actual value is not a float
-
toLongValue
Turns this iterator to a long value.- Returns:
- the long value
- Throws:
IOException- if the actual value is not a long
-
toBooleanValue
Turns this iterator to a boolean value.- Returns:
- the boolean value
- Throws:
IOException- if the actual value is not a boolean
-
toIntValue
Turns this iterator to an int value.- Returns:
- the int value
- Throws:
IOException- if the actual value is not an int
-
toBigIntegerValue
Turns this iterator to a big integer value.- Returns:
- the big integer value
- Throws:
IOException- if the actual value is not a big integer
-
toBigDecimalValue
Turns this iterator to a big decimal value.- Returns:
- the big decimal value
- Throws:
IOException- if the actual value is not a big decimal
-
asMap
Turns the full iterator into a map of objects.- Returns:
- the data as map; types may be larger than expected, e.g., int may be returned as long; arrays are
returned as list, objects as
Map<String, Object> - Throws:
IOException- if reading fails
-