Class JsonObject

java.lang.Object
io.helidon.json.JsonValue
io.helidon.json.JsonObject

public final class JsonObject extends JsonValue
Represents a JSON object value containing key-value pairs.

This module is incubating. These APIs may change in any version of Helidon, including backward incompatible changes.

  • Method Details

    • builder

      public static JsonObject.Builder builder()
      Create a new JsonObject.Builder for fluent construction of JsonObject instances.
      Returns:
      a new JsonObject.Builder
    • create

      public static JsonObject create(Map<String,JsonValue> content)
      Create a JsonObject from a map of string keys to JsonValue instances.
      Parameters:
      content - the map containing the object properties
      Returns:
      a new JsonObject
    • empty

      public static JsonObject empty()
      Returns the shared empty JSON object instance.
      Returns:
      the empty JSON object
    • containsKey

      public boolean containsKey(String key)
      Checks if this object contains the specified key.
      Parameters:
      key - the key to check for
      Returns:
      true if the object contains the key, false otherwise
    • value

      public JsonValue value(String key, JsonValue defaultValue)
      Return the value associated with the specified key, or the default value if the key is not present.
      Parameters:
      key - the key to look up
      defaultValue - the value to return if the key is not present
      Returns:
      the value associated with the key, or the default value
    • booleanValue

      public Optional<Boolean> booleanValue(String key)
      Return the boolean value associated with the specified key as an Optional.
      Parameters:
      key - the key to look up
      Returns:
      an Optional containing the boolean value, or empty if the key is not present
    • booleanValue

      public boolean booleanValue(String key, boolean defaultValue)
      Return the boolean value associated with the specified key, or the default value if the key is not present.
      Parameters:
      key - the key to look up
      defaultValue - the value to return if the key is not present
      Returns:
      the boolean value associated with the key, or the default value
    • objectValue

      public Optional<JsonObject> objectValue(String key)
      Return the JsonObject value associated with the specified key as an Optional.
      Parameters:
      key - the key to look up
      Returns:
      an Optional containing the JsonObject value, or empty if the key is not present
    • objectValue

      public JsonObject objectValue(String key, JsonObject defaultValue)
      Return the JsonObject value associated with the specified key, or the default value if the key is not present.
      Parameters:
      key - the key to look up
      defaultValue - the value to return if the key is not present
      Returns:
      the JsonObject value associated with the key, or the default value
    • stringValue

      public Optional<String> stringValue(String key)
      Return the string value associated with the specified key as an Optional.
      Parameters:
      key - the key to look up
      Returns:
      an Optional containing the string value, or empty if the key is not present
    • stringValue

      public String stringValue(String key, String defaultValue)
      Return the string value associated with the specified key, or the default value if the key is not present.
      Parameters:
      key - the key to look up
      defaultValue - the value to return if the key is not present
      Returns:
      the string value associated with the key, or the default value
    • intValue

      public Optional<Integer> intValue(String key)
      Return the integer value associated with the specified key as an Optional.
      Parameters:
      key - the key to look up
      Returns:
      an Optional containing the integer value, or empty if the key is not present
    • intValue

      public int intValue(String key, int defaultValue)
      Return the integer value associated with the specified key, or the default value if the key is not present.
      Parameters:
      key - the key to look up
      defaultValue - the value to return if the key is not present
      Returns:
      the integer value associated with the key, or the default value
    • doubleValue

      public Optional<Double> doubleValue(String key)
      Return the double value associated with the specified key as an Optional.
      Parameters:
      key - the key to look up
      Returns:
      an Optional containing the double value, or empty if the key is not present
    • doubleValue

      public double doubleValue(String key, double defaultValue)
      Return the double value associated with the specified key, or the default value if the key is not present.
      Parameters:
      key - the key to look up
      defaultValue - the value to return if the key is not present
      Returns:
      the double value associated with the key, or the default value
    • numberValue

      public Optional<BigDecimal> numberValue(String key)
      Return the BigDecimal value associated with the specified key as an Optional.
      Parameters:
      key - the key to look up
      Returns:
      an Optional containing the BigDecimal value, or empty if the key is not present
    • numberValue

      public BigDecimal numberValue(String key, BigDecimal defaultValue)
      Return the BigDecimal value associated with the specified key, or the default value if the key is not present.
      Parameters:
      key - the key to look up
      defaultValue - the value to return if the key is not present
      Returns:
      the BigDecimal value associated with the key, or the default value
    • arrayValue

      public Optional<JsonArray> arrayValue(String key)
      Return the JsonArray value associated with the specified key as an Optional.
      Parameters:
      key - the key to look up
      Returns:
      an Optional containing the JsonArray value, or empty if the key is not present
    • arrayValue

      public JsonArray arrayValue(String key, JsonArray defaultValue)
      Return the JsonArray value associated with the specified key, or the default value if the key is not present.
      Parameters:
      key - the key to look up
      defaultValue - the value to return if the key is not present
      Returns:
      the JsonArray value associated with the key, or the default value
    • keys

      public Set<JsonString> keys()
      Return a set of all keys in this object as JsonString instances.
      Returns:
      a set of JsonString keys
    • keysAsStrings

      public Set<String> keysAsStrings()
      Return a set of all keys in this object as String instances.
      Returns:
      a set of String keys
    • size

      public int size()
      Return the number of properties in this object.
      Returns:
      the size of this object
    • type

      public JsonValueType type()
      Description copied from class: JsonValue
      Return the type of this JSON value.
      Specified by:
      type in class JsonValue
      Returns:
      the JsonValueType of this value
    • toJson

      public void toJson(JsonGenerator generator)
      Description copied from class: JsonValue
      Write this JSON value to the provided generator.
      Specified by:
      toJson in class JsonValue
      Parameters:
      generator - the generator to write to
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object