Interface Hson.Struct

All Superinterfaces:
Hson.Value<Hson.Struct>
Enclosing class:
Hson

public static sealed interface Hson.Struct extends Hson.Value<Hson.Struct>
HSON Struct.

A representation of a struct, with possible child values. This is similar to JsonObject in JSON-P.

  • Method Details

    • builder

      static Hson.Struct.Builder builder()
      A new fluent API builder to construct a HSON Struct.
      Returns:
      a new builder
    • create

      static Hson.Struct create()
      Create an empty struct.
      Returns:
      new empty instance
    • value

      Optional<Hson.Value<?>> value(String key)
      Get a value.
      Parameters:
      key - key under this struct
      Returns:
      value of that key, or empty if not present; may return value that represents null
      See Also:
    • booleanValue

      Optional<Boolean> booleanValue(String key)
      Get a boolean value.
      Parameters:
      key - key under this struct
      Returns:
      boolean value if present
      Throws:
      HsonException - in case the key exists, but is not a boolean
    • booleanValue

      boolean booleanValue(String key, boolean defaultValue)
      Get a boolean value with default if not defined.
      Parameters:
      key - key under this struct
      defaultValue - default value to use if the key does not exist
      Returns:
      boolean value, or default value if the key does not exist
      Throws:
      HsonException - in case the key exists, but is not a Hson.Type.BOOLEAN
    • structValue

      Optional<Hson.Struct> structValue(String key)
      Get struct value. If the value represents null, returns empty optional.
      Parameters:
      key - key under this struct
      Returns:
      struct value if present
      Throws:
      HsonException - in case the key exists, but is not a Hson.Type.STRUCT
    • stringValue

      Optional<String> stringValue(String key)
      Get string value.
      Parameters:
      key - key under this struct
      Returns:
      string value if present
      Throws:
      HsonException - in case the key exists, but is not a Hson.Type.STRING
    • stringValue

      String stringValue(String key, String defaultValue)
      Get a string value with default if not defined.
      Parameters:
      key - key under this struct
      defaultValue - default value to use if the key does not exist
      Returns:
      string value, or default value if the key does not exist
      Throws:
      HsonException - in case the key exists, but is not a Hson.Type.STRING
    • intValue

      Optional<Integer> intValue(String key)
      Get int value.
      Parameters:
      key - key under this struct
      Returns:
      int value if present, from BigDecimal.intValue()
      Throws:
      HsonException - in case the key exists, but is not a Hson.Type.NUMBER
    • intValue

      int intValue(String key, int defaultValue)
      Get an int value with default if not defined.
      Parameters:
      key - key under this struct
      defaultValue - default value to use if the key does not exist
      Returns:
      int value, or default value if the key does not exist
      Throws:
      HsonException - in case the key exists, but is not a Hson.Type.NUMBER
      See Also:
    • doubleValue

      Optional<Double> doubleValue(String key)
      Get double value.
      Parameters:
      key - key under this struct
      Returns:
      double value if present, from BigDecimal.doubleValue()
      Throws:
      HsonException - in case the key exists, but is not a Hson.Type.NUMBER
    • doubleValue

      double doubleValue(String key, double defaultValue)
      Get a double value with default if not defined (or null).
      Parameters:
      key - key under this struct
      defaultValue - default value to use if the key does not exist
      Returns:
      double value, or default value if the key does not exist
      Throws:
      HsonException - in case the key exists, but is not a Hson.Type.NUMBER
      See Also:
    • numberValue

      Optional<BigDecimal> numberValue(String key)
      Get number value.
      Parameters:
      key - key under this struct
      Returns:
      big decimal value if present
      Throws:
      HsonException - in case the key exists, but is not a Hson.Type.NUMBER
    • numberValue

      BigDecimal numberValue(String key, BigDecimal defaultValue)
      Get number value with default if not defined (or null).
      Parameters:
      key - key under this struct
      defaultValue - default value to use if not present or null
      Returns:
      big decimal value
    • stringArray

      Optional<List<String>> stringArray(String key)
      Get string array value.
      Parameters:
      key - key under this struct
      Returns:
      string array value, if the key exists
      Throws:
      HsonException - in case the key exists, is an array, but elements are not strings
      HsonException - in case the key exists, but is not an array
    • structArray

      Optional<List<Hson.Struct>> structArray(String key)
      Get struct array value.
      Parameters:
      key - key under this struct
      Returns:
      struct array value, if the key exists
      Throws:
      HsonException - in case the key exists, is an array, but elements are not structs
      HsonException - in case the key exists, but is not an array
    • numberArray

      Optional<List<BigDecimal>> numberArray(String key)
      Get number array value.
      Parameters:
      key - key under this struct
      Returns:
      number array value, if the key exists
      Throws:
      HsonException - in case the key exists, is an array, but elements are not numbers
      HsonException - in case the key exists, but is not an array
    • booleanArray

      Optional<List<Boolean>> booleanArray(String key)
      Get boolean array value.
      Parameters:
      key - key under this struct
      Returns:
      boolean array value, if the key exists
      Throws:
      HsonException - in case the key exists, is an array, but elements are not booleans
      HsonException - in case the key exists, but is not an array
    • arrayValue

      Optional<Hson.Array> arrayValue(String key)
      Get array value.
      Parameters:
      key - key under this struct
      Returns:
      array value, if the key exists
      Throws:
      HsonException - in case the key exists, but is not an array