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.