Class JSONObjectImpl

java.lang.Object
org.tquadrat.foundation.jsonbuilder.internal.JSONObjectImpl
All Implemented Interfaces:
Iterable<JSONValue>, Formattable, JSONObject, JSONValue

@ClassVersion(sourceVersion="$Id: JSONObjectImpl.java 1195 2026-04-15 21:33:40Z tquadrat $") @API(status=INTERNAL, since="0.25.0") public final class JSONObjectImpl extends Object implements JSONObject

The implementation for the interface JSONObject.

Author:
Thomas Thrien (thomas.thrien@tquadrat.org)
Version:
$Id: JSONObjectImpl.java 1195 2026-04-15 21:33:40Z tquadrat $
Since:
0.25.0
UML Diagram
UML Diagram for "org.tquadrat.foundation.jsonbuilder.internal.JSONObjectImpl"

UML Diagram for "org.tquadrat.foundation.jsonbuilder.internal.JSONObjectImpl"

UML Diagram for "org.tquadrat.foundation.jsonbuilder.internal.JSONObjectImpl"
  • Field Details

  • Constructor Details

    • JSONObjectImpl

      Creates a new instance of JSONObjectImpl.
      Parameters:
      builder - The reference to the JSONBuilder.
    • JSONObjectImpl

      {summary Creates a new instance of JSONObjectImpl from the given other object.}

      The new object is a deep copy of the given instance.

      Parameters:
      other - The other JSON object.
  • Method Details

    • contains

      public final boolean contains(String name)

      Checks if a specified member is present as a child of this object. This will not test if that child is the JSON literal null, This needs to be tested separately.

      Specified by:
      contains in interface JSONObject
      Parameters:
      name - The name of the member to check for.
      Returns:
      true if there is a member with the given name, false if not.
    • equals

      public final boolean equals(Object o)
      Overrides:
      equals in class Object
    • formatTo

      public void formatTo(Formatter formatter, int flags, int width, int precision)
      Specified by:
      formatTo in interface Formattable
      Specified by:
      formatTo in interface JSONValue
    • get

      public final Optional<JSONValue> get(String name)

      Returns the value of the member with the specified name in this object.

      Specified by:
      get in interface JSONObject
      Parameters:
      name - The name of the member whose value is to be returned.
      Returns:
      An instance of Optional that holds the value.
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • isEmpty

      public final boolean isEmpty()
      Checks whether this object has members.
      Specified by:
      isEmpty in interface JSONObject
      Returns:
      true if the object does not have any members, false otherwise.
    • iterator

      public final Iterator<JSONValue> iterator()
      Specified by:
      iterator in interface Iterable<JSONValue>
    • merge

      public JSONObject merge(JSONObject object)

      Copies all members of the specified object into this object. When the specified object contains members with names that also exist in this object, the existing values in this object will be replaced by the corresponding values in the specified object.

      Specified by:
      merge in interface JSONObject
      Parameters:
      object - The object to merge.
      Returns:
      This object itself, to enable method chaining.
    • names

      public final SequencedCollection<String> names()

      Returns the names of the members of this object in document order.

      The return value is backed by this object and will reflect subsequent changes. It cannot be used to modify this object. Attempts to modify the returned data structure will result in an exception.

      Specified by:
      names in interface JSONObject
      Returns:
      The names.
    • remove

      public final JSONObject remove(String name)

      Removes a member with the specified name from this object. If this object does not contain a member with the specified name, the object is not modified.

      Specified by:
      remove in interface JSONObject
      Parameters:
      name - The name of the member to remove.
      Returns:
      This object itself, to enable method chaining.
    • set

      public final JSONObject set(String name, BigDecimal value)

      Sets the value of the member with the specified name to the JSON representation of the specified BigDecimal value.

      If this object does not contain a member with this name, a new member is added at the end of the object.

      Specified by:
      set in interface JSONObject
      Parameters:
      name - The name of the member to replace or to add.
      value - The value to set to the member.
      Returns:
      This object itself, to enable method chaining.
    • set

      public final JSONObject set(String name, BigInteger value)

      Sets the value of the member with the specified name to the JSON representation of the specified BigInteger value.

      If this object does not contain a member with this name, a new member is added at the end of the object.

      Specified by:
      set in interface JSONObject
      Parameters:
      name - The name of the member to replace or to add.
      value - The value to set to the member.
      Returns:
      This object itself, to enable method chaining.
    • set

      public <T extends Dimension> JSONObject set(String name, DimensionedValue<T> value, T targetUnit)

      Sets the value of the member with the specified name to the JSON representation of the specified DimensionedValue value.

      If this object does not contain a member with this name, a new member is added at the end of the object.

      Specified by:
      set in interface JSONObject
      Type Parameters:
      T - The type of the dimension for the value.
      Parameters:
      name - The name of the member to replace or to add.
      value - The value.
      targetUnit - The dimension for the output.
      Returns:
      This object itself, to enable method chaining.
      See Also:
    • set

      public final JSONObject set(String name, double value)

      Sets the value of the member with the specified name to the JSON representation of the specified double value.

      If this object does not contain a member with this name, a new member is added at the end of the object.

      Specified by:
      set in interface JSONObject
      Parameters:
      name - The name of the member to replace or to add.
      value - The value to set to the member.
      Returns:
      This object itself, to enable method chaining.
    • set

      public final JSONObject set(String name, Double value)

      Sets the value of the member with the specified name to the JSON representation of the specified Double value.

      If this object does not contain a member with this name, a new member is added at the end of the object.

      Specified by:
      set in interface JSONObject
      Parameters:
      name - The name of the member to replace or to add.
      value - The value to set to the member.
      Returns:
      This object itself, to enable method chaining.
    • set

      public final JSONObject set(String name, float value)

      Sets the value of the member with the specified name to the JSON representation of the specified float value.

      If this object does not contain a member with this name, a new member is added at the end of the object.

      Specified by:
      set in interface JSONObject
      Parameters:
      name - The name of the member to replace or to add.
      value - The value to set to the member.
      Returns:
      This object itself, to enable method chaining.
    • set

      public final JSONObject set(String name, Float value)

      Sets the value of the member with the specified name to the JSON representation of the specified Float value.

      If this object does not contain a member with this name, a new member is added at the end of the object.

      Specified by:
      set in interface JSONObject
      Parameters:
      name - The name of the member to replace or to add.
      value - The value to set to the member.
      Returns:
      This object itself, to enable method chaining.
    • set

      public final JSONObject set(String name, int value)

      Sets the value of the member with the specified name to the JSON representation of the specified int value.

      If this object does not contain a member with this name, a new member is added at the end of the object.

      Specified by:
      set in interface JSONObject
      Parameters:
      name - The name of the member to replace or to add.
      value - The value to set to the member.
      Returns:
      This object itself, to enable method chaining.
    • set

      public final JSONObject set(String name, Integer value)

      Sets the value of the member with the specified name to the JSON representation of the specified Integer value.

      If this object does not contain a member with this name, a new member is added at the end of the object.

      Specified by:
      set in interface JSONObject
      Parameters:
      name - The name of the member to replace or to add.
      value - The value to set to the member.
      Returns:
      This object itself, to enable method chaining.
    • set

      public final JSONObject set(String name, JSONValue value)

      Sets the value of the member with the specified name to the specified JSONValue value.

      If this object does not contain a member with this name, a new member is added at the end of the object.

      Specified by:
      set in interface JSONObject
      Parameters:
      name - The name of the member to replace or to add.
      value - The value to set to the member.
      Returns:
      This object itself, to enable method chaining.
    • set

      public final JSONObject set(String name, long value)

      Sets the value of the member with the specified name to the JSON representation of the specified long value.

      If this object does not contain a member with this name, a new member is added at the end of the object.

      Specified by:
      set in interface JSONObject
      Parameters:
      name - The name of the member to replace or to add.
      value - The value to set to the member.
      Returns:
      This object itself, to enable method chaining.
    • set

      public final JSONObject set(String name, Long value)

      Sets the value of the member with the specified name to the JSON representation of the specified Long value.

      If this object does not contain a member with this name, a new member is added at the end of the object.

      Specified by:
      set in interface JSONObject
      Parameters:
      name - The name of the member to replace or to add.
      value - The value to set to the member.
      Returns:
      This object itself, to enable method chaining.
    • set

      public final JSONObject set(String name, String value)

      Sets the value of the member with the specified name to the JSON representation of the specified String value.

      If this object does not contain a member with this name, a new member is added at the end of the object.

      Specified by:
      set in interface JSONObject
      Parameters:
      name - The name of the member to replace or to add.
      value - The value to set to the member.
      Returns:
      This object itself, to enable method chaining.
    • setArray

      public final JSONArray setArray(String name)

      Sets a new empty instance of JSONArray to this object and returns that.

      Specified by:
      setArray in interface JSONObject
      Parameters:
      name - The name of the member.
      Returns:
      The freshly created JSONArray.
    • setObject

      public final JSONObject setObject(String name)

      Sets a new empty instance of JSONObject to this object and returns that.

      Specified by:
      setObject in interface JSONObject
      Parameters:
      name - The name of the member.
      Returns:
      The freshly created JSONObject.
    • size

      public final int size()

      Returns the number of members (name/value pairs) in this object.

      Specified by:
      size in interface JSONObject
      Returns:
      The number of members in this object.
    • toString

      public final String toString()
      Specified by:
      toString in interface JSONValue
      Overrides:
      toString in class Object