Interface JsonObjectBuilder

All Superinterfaces:
Iterable<JsonField>, JsonValueContainer<JsonField>

public interface JsonObjectBuilder extends JsonValueContainer<JsonField>
A mutable builder for a JsonObject. Implementations of this interface are normally not thread safe and not reusable. The order in which the key-value-pairs are set is preserved in the resulting JSON object.
  • Method Details

    • set

      JsonObjectBuilder set(CharSequence key, int value, Predicate<JsonField> predicate)
      Sets a new int value field to the JSON object to be built if the specified predicate evaluates to true.
      Parameters:
      key - the JSON key or JSON pointer of the field to be set.
      value - the value to be set.
      predicate - the predicate which finally determines if the value is to be set.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if keyOrPointer or predicate is null.
      IllegalArgumentException - if key is empty or if key is an empty JsonPointer. Setting a value with slash as JsonKey object explicitly works.
    • set

      default JsonObjectBuilder set(CharSequence key, int value)
      Sets a new int value field to the JSON object to be built.
      Parameters:
      key - the JSON key or JSON pointer of the field to be set.
      value - the value to be set.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if key is null.
      IllegalArgumentException - if key is empty or if key is an empty JsonPointer. Setting a value with slash as JsonKey object explicitly works.
    • set

      JsonObjectBuilder set(CharSequence key, long value, Predicate<JsonField> predicate)
      Sets a new long value field to the JSON object to be built if the specified predicate evaluates to true.
      Parameters:
      key - the JSON key or JSON pointer of the field to be set.
      value - the value to be set.
      predicate - the predicate which finally determines if the value is to be set.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if key or predicate is null.
      IllegalArgumentException - if key is empty or if key is an empty JsonPointer. Setting a value with slash as JsonKey object explicitly works.
    • set

      default JsonObjectBuilder set(CharSequence key, long value)
      Sets a new long value field to the JSON object to be built.
      Parameters:
      key - the JSON key or JSON pointer of the field to be set.
      value - the value to be set.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if key is null.
      IllegalArgumentException - if key is empty or if key is an empty JsonPointer. Setting a value with slash as JsonKey object explicitly works.
    • set

      JsonObjectBuilder set(CharSequence key, double value, Predicate<JsonField> predicate)
      Sets a new double value field to the JSON object to be built if the specified predicate evaluates to true.
      Parameters:
      key - the JSON key or JSON pointer of the field to be set.
      value - the value to be set.
      predicate - the predicate which finally determines if the field is to be set.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if key or predicate is null.
      IllegalArgumentException - if key is empty or if key is an empty JsonPointer. Setting a value with slash as JsonKey object explicitly works.
    • set

      default JsonObjectBuilder set(CharSequence key, double value)
      Sets a new double value field to the JSON object to be built.
      Parameters:
      key - the JSON key or JSON pointer of the field to be set.
      value - the value to be set.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if key is null.
      IllegalArgumentException - if key is empty or if key is an empty JsonPointer. Setting a value with slash as JsonKey object explicitly works.
    • set

      JsonObjectBuilder set(CharSequence key, boolean value, Predicate<JsonField> predicate)
      Sets a new boolean value field to the JSON object to be built if the specified predicate evaluates to true.
      Parameters:
      key - the JSON key or JSON pointer of the field to be set.
      value - the value to be set.
      predicate - the predicate which finally determines if the value is to be set.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if key or predicate is null.
      IllegalArgumentException - if key is empty or if key is an empty JsonPointer. Setting a value with slash as JsonKey object explicitly works.
    • set

      default JsonObjectBuilder set(CharSequence key, boolean value)
      Sets a new boolean value field to the JSON object to be built.
      Parameters:
      key - the JSON key or JSON pointer of the field to be set.
      value - the value to be set.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if key is null.
      IllegalArgumentException - if key is empty or if key is an empty JsonPointer. Setting a value with slash as JsonKey object explicitly works.
    • set

      Sets a new string value field to the JSON object to be built if the specified predicate evaluates to true.
      Parameters:
      key - the JSON key or JSON pointer of the field to be set.
      value - the value to be set.
      predicate - the predicate which finally determines if the field is to be set.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if key or predicate is null.
      IllegalArgumentException - if key is empty or if key is an empty JsonPointer. Setting a value with slash as JsonKey object explicitly works.
    • set

      default JsonObjectBuilder set(CharSequence key, @Nullable String value)
      Sets a new string value field to the JSON object to be built.
      Parameters:
      key - the JSON key or JSON pointer of the field to be set.
      value - the value to be set.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if key is null.
      IllegalArgumentException - if key is empty or if key is an empty JsonPointer. Setting a value with slash as JsonKey object explicitly works.
    • set

      Sets a new JsonValue field to the JSON object to be built if the specified predicate evaluates to true.
      Parameters:
      key - the JSON key or JSON pointer of the field to be set.
      value - the value to be set.
      predicate - the predicate which finally determines if the field is to be set.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if any argument is null; the predicate is evaluated before the null check of the value.
      IllegalArgumentException - if key is empty or if key is an empty JsonPointer. Setting a value with slash as JsonKey object explicitly works.
    • set

      default JsonObjectBuilder set(CharSequence key, JsonValue value)
      Sets a new JsonValue field to the JSON object to be built.
      Parameters:
      key - the JSON key or JSON pointer of the field to be set.
      value - the value of the field to be set.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if any argument is null.
      IllegalArgumentException - if key is empty or if key is an empty JsonPointer. Setting a value with slash as JsonKey object explicitly works.
    • set

      <T> JsonObjectBuilder set(JsonFieldDefinition<T> fieldDefinition, @Nullable T value, Predicate<JsonField> predicate)
      Sets a new field to the JSON object to be built if the specified predicate evaluates to true.
      Type Parameters:
      T - the type of value.
      Parameters:
      fieldDefinition - defines the location via JsonPointer, the Java value type and optional JsonFieldMarkers of the field to be set.
      value - the value of the field to be set.
      predicate - the predicate which finally determines if the field is to be set. The field was derived from fieldDefinition and value.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if fieldDefinition or predicate is null.
      IllegalArgumentException - if the value type of fieldDefinition is not a int.
      See Also:
    • set

      default <T> JsonObjectBuilder set(JsonFieldDefinition<T> fieldDefinition, @Nullable T value)
      Sets a new field to the JSON object to be built.
      Type Parameters:
      T - the type of value.
      Parameters:
      fieldDefinition - defines the location via JsonPointer, the Java value type and optional JsonFieldMarkers of the field to be set.
      value - the value of the field to be set.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if fieldDefinition or predicate is null.
      IllegalArgumentException - if the value type of fieldDefinition is not a int.
      See Also:
    • set

      Sets the specified field to the JSON object to be built if the specified predicate evaluates to true. If this builder already contains a field with the same key, the existing one will be replaced.
      Parameters:
      field - the field to be set.
      predicate - the predicate which finally determines if the field is to be set.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if any argument is null.
    • set

      default JsonObjectBuilder set(JsonField field)
      Sets the specified field to the JSON object to be built. If this builder already contains a field with the same key, the existing one will be replaced.
      Parameters:
      field - the field to be set.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if field is null.
    • remove

      Removes the field from the JSON object to be built which is associated with the given key. This method has no effect if no such field exists.
      Parameters:
      key - the key of the field to be removed.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if key is null.
    • remove

      JsonObjectBuilder remove(JsonFieldDefinition<?> fieldDefinition)
      Removes the field from the JSON object to be built which is associated with the pointer of the specified JSON field definition. This method has no effect if no such field exists.
      Parameters:
      fieldDefinition - provides the JSON pointer of the field to be deleted.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if fieldDefinition is null.
      IllegalArgumentException - if the JSON pointer of fieldDefinition is empty.
    • setAll

      JsonObjectBuilder setAll(Iterable<JsonField> fields, Predicate<JsonField> predicate)
      Sets the given JsonFields to the JSON object to be built. This method prevents duplicates, i. e. if two fields have the same key, the previous field is replaced by the new field; the position of the new field in the resulting JSON object is the same as the position of the previous field. For each field applies that the field is only set if the specified predicate evaluates to true.
      Parameters:
      fields - the fields to set.
      predicate - the predicate which finally determines for each field if it is to be set.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if any argument is null.
    • setAll

      default JsonObjectBuilder setAll(Iterable<JsonField> fields)
      Sets the given JsonFields to the JSON object to be built. This method prevents duplicates, i. e. if two fields have the same key, the previous field is replaced by the new field; the position of the new field in the resulting JSON object is the same as the position of the previous field.
      Parameters:
      fields - the fields to set.
      Returns:
      this builder to allow method chaining.
      Throws:
      NullPointerException - if fields is null.
    • removeAll

      JsonObjectBuilder removeAll()
      Removes all fields from the JSON object to be built.
      Returns:
      this builder to allow method chaining.
    • build

      JsonObject build()
      Creates a new JsonObject containing all values which were added beforehand.
      Returns:
      a new JSON object.