Interface JsonDocumentReader

All Superinterfaces:
Iterator<JsonDocumentItemType>
All Known Implementing Classes:
OsonDocumentReader, StringJsonDocumentReader

public interface JsonDocumentReader extends Iterator<JsonDocumentItemType>
JSON document reader. Reads a JSON document (i.e., String or OSON bytes) and produce Json item type event. Calling #next() will return one of a JsonDocumentItem.JsonDocumentItemType. The sequence of return types follows JSON specification.

When JsonDocumentItemType.VALUE_KEY is returned #getObjectKeyName() should be called to get the key name.

When JsonDocumentItemType.VALUE, JsonDocumentItemType.BOOLEAN_VALUE, JsonDocumentItemType.NULL_VALUE or JsonDocumentItemType.NUMERIC_VALUE is returned one of the getxxxValue() should be called to get the value.

example :

{
          "key1": "value1",
          "key2": ["x","y","z"],
          "key3": {
            "key4" : ["a"],
            "key5" : {}
           },
   "key6":12,
   "key7":null
 }
 
This Json object could be read as follows
     while (reader.hasNext()) {}
        JsonDocumentItemType type = reader.next();
        switch(type) {
                   case VALUE_KEY:
                       String keyName = reader.getObjectKeyName();
                       break;
                   case VALUE:
                       String value = reader.getStringValue()
                       break
                    //...
        }
     }
 
This Json object above would trigger this sequence of events
   JsonDocumentItemType.OBJECT_START
   JsonDocumentItemType.VALUE_KEY      // "key1"
   JsonDocumentItemType.VALUE          // "value1"
   JsonDocumentItemType.VALUE_KEY      // "key2"
   JsonDocumentItemType.ARRAY_START
   JsonDocumentItemType.VALUE          // "x"
   JsonDocumentItemType.VALUE          // "y"
   JsonDocumentItemType.VALUE          // "z"
   JsonDocumentItemType.ARRAY_END
   JsonDocumentItemType.VALUE_KEY      // "key3"
   JsonDocumentItemType.OBJECT_START
   JsonDocumentItemType.VALUE_KEY      // "key4"
   JsonDocumentItemType.ARRAY_START
   JsonDocumentItemType.VALUE          // "a"
   JsonDocumentItemType.ARRAY_END
   JsonDocumentItemType.VALUE_KEY       // "key5"
   JsonDocumentItemType.OBJECT_START
   JsonDocumentItemType.OBJECT_END
   JsonDocumentItemType.VALUE_KEY       // "key6"
   JsonDocumentItemType.NUMERIC_VALUE
   JsonDocumentItemType.VALUE_KEY       // "key7"
   JsonDocumentItemType.NULL_VALUE
   JsonDocumentItemType.OBJECT_END
   JsonDocumentItemType.OBJECT_END
 
  • Method Details

    • forEachRemaining

      default void forEachRemaining()
    • getObjectKeyName

      String getObjectKeyName()
      Gets the key name once JsonDocumentItemType.VALUE_KEY has been received
      Returns:
      the name
    • getStringValue

      String getStringValue()
      Gets value as String
      Returns:
      the value.
    • getBigDecimalValue

      BigDecimal getBigDecimalValue()
      Gets value as BigDecimal
      Returns:
      the value.
    • getBigIntegerValue

      BigInteger getBigIntegerValue()
      Gets value as BigInteger
      Returns:
      the value.
    • getDoubleValue

      double getDoubleValue()
      Gets value as double
      Returns:
      the value.
    • getFloatValue

      float getFloatValue()
      Gets value as float
      Returns:
      the value.
    • getLongValue

      long getLongValue()
      Gets value as long
      Returns:
      the value.
    • getIntegerValue

      int getIntegerValue()
      Gets value as int
      Returns:
      the value.
    • getShortValue

      short getShortValue()
      Gets value as short
      Returns:
      the value.
    • getByteValue

      byte getByteValue()
      Gets value as byte
      Returns:
      the value.
    • getBooleanValue

      boolean getBooleanValue()
      Gets value as boolean
      Returns:
      the value.
    • getValue

      <T> T getValue(JavaType<T> javaType, WrapperOptions options)
      Gets value as JavaType
      Returns:
      the value.