Interface UpdateConstraint.PartialJSON

All Superinterfaces:
UpdateConstraint
Enclosing interface:
UpdateConstraint

public static interface UpdateConstraint.PartialJSON extends UpdateConstraint
A constraint requiring the current value of a JSON topic to match the partially described value.

The code:

 
 Constraint.Factory factory = Diffusion.updateConstraints();
 PartialJSON constraint =
     factory.jsonValue()
         .with("/id", String.class, idValue)
         .without("/cancellation");
 
 
creates a constraint for a JSON object with a specific ID value and no value for a "cancellation" property.

Missing keys are matched differently to keys that are present with null values.

  • Method Details

    • with

      @Deprecated <V> UpdateConstraint.PartialJSON with(String pointer, Class<V> valueClass, V value)
      Deprecated.
      since 6.10

      Rather use the with(String, Operator, Object) method with the IS operator.

      Require a value at a specific position in the JSON object.

      This is equivalent to calling with(String, Operator, Object) with an operator of IS.

      Type Parameters:
      V - the value type of the value at the pointer
      Parameters:
      pointer - the pointer expression
      valueClass - this parameter is no longer used and is ignored
      value - the value
      Returns:
      a new constraint
      Throws:
      IllegalArgumentException - if the pointer parameter cannot be parsed as a JSON pointer or if the class of the supplied value is not supported
    • with

      Compares a location within the JSON topic value to a specified value.

      If there is no value found at the specified pointer position, the constraint will be unsatisfied.

      If a String value is supplied and the operator is EQ or NE, the string representation of the topic value at the given pointer will be compared to the supplied value. If the value at the pointer position is not a string or number the constraint will be unsatisfied. Other operators (other than IS) are not permitted with String values.

      If a number value (Integer, Long or Double) is supplied the value will be compared with the number value at the topic location. This will work with JSON string or number values only. JSON strings can only be compared if they contain a value that can be parsed as a number. If a string value at the location cannot be parsed as a number, the constraint will be unsatisfied. Any of the operators (other than IS) can be used with such number comparisons. Decimal numbers can be compared with integral numbers so 1 is equal to 1.0, "1", or "1.0".

      If a null value is supplied and the operator is EQ or NE, the topic value at the given pointer will be compared to JSON null. Other operators (other than IS) are not permitted with a null value.

      If a Boolean value is supplied and the operator is EQ, the topic value at the given pointer will be compared to the boolean value. Other operators are not permitted with a boolean value.

      If the IS operator is specified the supplied value will be compared to the topic value for strict binary equality. In this case the value must be of type String, Integer, Long, Double, Bytes, or null. This is slightly more efficient than the lenient comparisons described above.

      Parameters:
      pointer - a JSON Pointer specifying the location of the value in the JSON object.
      operator - the operator that determines the type of comparison
      value - the value
      Returns:
      a new constraint
      Throws:
      IllegalArgumentException - if the pointer parameter cannot be parsed as a JSON pointer, the value type is not supported, or the operator is not compatible with the value type
      Since:
      6.10
    • without

      Require a specific position in the JSON object to be absent. This does not match positions that have null values.

      The pointer is a JSON Pointer syntax reference that should have no value in the JSON object.

      Parameters:
      pointer - the pointer expression
      Returns:
      a new constraint
      Throws:
      IllegalArgumentException - if the pointer parameter cannot be parsed as a JSON pointer