Interface IValueBuilderOptions


public interface IValueBuilderOptions
Options for a value builder that lets you create a value conforming to a IValueDescriptor. It lets you configure some details of how the value will be created.
Since:
8.5.0
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the acceptance criteria that the created value must satisfy.
    boolean
    Gets whether the created value should be mutable.
  • Method Details

    • acceptanceCriteria

      IValueAcceptanceCriteria acceptanceCriteria()
      Gets the acceptance criteria that the created value must satisfy. The builder will ensure that the value it produces will meet these criteria. Defaults to a strict set of acceptance criteria. There are use cases where you might want to relax these criteria. For example, a builder for a record value will ignore all extraneous fields. If you want to preserve such fields, you can allow extraneousRecord fields in the acceptance criteria.
      // A simple descriptor that allows a single field "age" of type integer with default value 18.
      var f = ValueDescriptorFactory.getInstance();
      var descriptor = f.recordBuilder().requiredProperty("age", f.integer(18)).build();
      
      // We got a value from somewhere that has the wrong type for "age" and an extraneous field "name".
      // We want to ensure the known properties have the right type, but preserve extraneous fields.
      var originalValue = Map.of("age", "shouldBeAnInteger", "name", "extraneousField");
      var criteria = ValueAcceptanceCriteria.builder().allowExtraneousRecordFields(true).build();
      var options = ValueBuilderOptions.configurator().acceptanceCriteria(criteria).create();
      var sanitizedValue = descriptor.builder(options).value(originalValue).build();
      
      // sanitizedValue is now:
      // Map.of("a", 18, "b", "extraneousField")
      
      Note: It is highly discouraged to disable conformance flags such as enforceMapValueConformance. Doing so may lead to values being created that do not conform to the value descriptor at all, which may lead to runtime errors or a ClassCastException later on.
      Returns:
      criteria The acceptance criteria that the created value must satisfy.
    • mutable

      boolean mutable()
      Gets whether the created value should be mutable. Note that not all value types support mutable values. In this case, the returned builder behaves as if mutable was false. In particular, the mutable flag is usually only supported for collection types (lists, maps, records). The default is false, i.e. the created value is immutable.
      Returns:
      Whether the created value should be mutable.