Interface IValueBuilderConfigurator


public interface IValueBuilderConfigurator
Configurator for a set of IValueBuilderOptions, for use with the builder obtained from a IValueDescriptor. Use methods from ValueBuilderOptions to obtain an instance of this interface. It lets you configure some details of how the value will be created.
Since:
8.5.0
  • Method Details

    • acceptanceCriteria

      Sets 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.
      Parameters:
      criteria - The acceptance criteria that the created value must satisfy.
      Returns:
      This configurator for method chaining.
    • create

      Creates a new value builder with the currently configured options.
      Returns:
      A new value builder.
    • immutable

      default IValueBuilderConfigurator immutable()
      Sets that the created value should be immutable. This is the default behavior. 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).
      Returns:
      This configurator for method chaining.
    • mutable

      default IValueBuilderConfigurator mutable()
      Sets that 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:
      This configurator for method chaining.
    • mutable

      IValueBuilderConfigurator mutable(boolean mutable)
      Sets 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.
      Parameters:
      mutable - Whether the created value should be mutable.
      Returns:
      This configurator for method chaining.