Interface JsonIterator


public interface JsonIterator
An iterable JSON structure. Abstraction based on Jsoniter.
Author:
Holger Eichelberger, SSE
  • Method Details

    • valueType

      Returns the value type.
      Returns:
      the value type
    • containsKey

      boolean containsKey(String key)
      Does the given key exist in the underlying JSON structure.
      Parameters:
      key - the key
      Returns:
      true if the key exist, false else
    • get

      JsonIterator get(String key)
      Returns the value of the given key. Use either iterator-based access or name-based access.
      Parameters:
      key - the key
      Returns:
      the value, may be null for none
    • slice

      byte[] slice(byte[] data, JsonIterator iter) throws IOException
      Slices data so that the nested part of iter remains.
      Parameters:
      data - the data
      iter - 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

      JsonIterator get(int index)
      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, see size()
    • entries

      Returns all entries. Use either iterator-based access or name-based access.
      Returns:
      all entries
    • getAnyKey

      String getAnyKey()
      Returns any key, in particular if size() is 1, the first/only key. Works only on objects.
      Returns:
      any key, may be null
    • toStringValue

      String toStringValue() throws IOException
      Turns this iterator to a string value.
      Returns:
      the string value
      Throws:
      IOException - if the actual value is not a string
    • toDoubleValue

      double toDoubleValue() throws IOException
      Turns this iterator to a double value.
      Returns:
      the double value
      Throws:
      IOException - if the actual value is not a double
    • toFloatValue

      float toFloatValue() throws IOException
      Turns this iterator to a float value.
      Returns:
      the float value
      Throws:
      IOException - if the actual value is not a float
    • toLongValue

      long toLongValue() throws IOException
      Turns this iterator to a long value.
      Returns:
      the long value
      Throws:
      IOException - if the actual value is not a long
    • toBooleanValue

      boolean toBooleanValue() throws IOException
      Turns this iterator to a boolean value.
      Returns:
      the boolean value
      Throws:
      IOException - if the actual value is not a boolean
    • toIntValue

      int toIntValue() throws IOException
      Turns this iterator to an int value.
      Returns:
      the int value
      Throws:
      IOException - if the actual value is not an int
    • toBigIntegerValue

      BigInteger toBigIntegerValue() throws IOException
      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

      BigDecimal toBigDecimalValue() throws IOException
      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

      Map<String,Object> asMap() throws IOException
      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