setPropertyValues method

void setPropertyValues(
  1. Map<String, Object?> values, {
  2. bool ignoreUnknown = false,
  3. bool ignoreInvalid = false,
})

Sets every entry; failures are collected into a PropertyBatchUpdateException.

ignoreUnknown skips unknown or read-only properties; ignoreInvalid skips paths through null values (Spring's setPropertyValues(pvs, ignoreUnknown, ignoreInvalid)).

wrapper.setPropertyValues(
  {'name': 'Ann', 'age': '30', 'unknown': 1},
  ignoreUnknown: true,
);

Implementation

void setPropertyValues(
  Map<String, Object?> values, {
  bool ignoreUnknown = false,
  bool ignoreInvalid = false,
}) {
  final failures = <BeansException>[];
  for (final MapEntry(:key, :value) in values.entries) {
    try {
      setPropertyValue(key, value);
    } on NotWritablePropertyException catch (error) {
      if (!ignoreUnknown) {
        failures.add(error);
      }
    } on NullValueInNestedPathException catch (error) {
      if (!ignoreInvalid) {
        failures.add(error);
      }
    } on BeansException catch (error) {
      failures.add(error);
    }
  }
  if (failures.isNotEmpty) {
    throw PropertyBatchUpdateException(failures);
  }
}