Value types

The @ValueType annotation is used to declare value types.

Value types must:

  • Be immutable and final.
  • Have implementations of hashcode and equals methods.

The value type fields must:

  • Be final.
  • Be of value type.
  • Be provided when the object is created.

When an external library is imported into Decision Designer, an automatic check is performed on value types to ensure that they fulfill these requirements.

The following example shows a class, Address, annotated with @ValueType:

@ValueType
public final class Address {

    public final String city;
    public final String street;
    public final String number;

    @BeanConstructor
    @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
    public Address(@JsonProperty("city") String city, 
                   @JsonProperty("street") String street, 
                   @JsonProperty("number") String number) {
        this.city = city;
        this.street = street;
        this.number = number;
    }

    @NotVerbalized
    @Override
    public boolean equals(Object object) {
        if (object instanceof Address) {
            Address address = (Address) object;
            return (Objects.equals(this.city, address.city) &&
                    Objects.equals(this.street, address.street) &&
                    Objects.equals(this.number, address.number));
        }
        return false;
    }
    
    @NotVerbalized
    @Override
    public int hashCode() {
        return Objects.hash(city, street, number);
    }
}

Assigning Address as a type to a data type in your data model would allow you to check whether two objects have the same values. When checking whether two objects of type Address are equal in the rule language, this test would succeed if the two objects have the same city, street, and number.