toBool static method
value as a bool for and, or, ! and the condition of ? ::
a bool as it is, anything typeConverter can turn into one
('true') converted; null and other values fail with
SpelMessage.typeConversionError.
SpelOperations.toBool(true); // true
SpelOperations.toBool('true'); // true
SpelOperations.toBool(null); // throws
Implementation
static bool toBool(Object? value, [TypeConverter? typeConverter]) {
if (value is bool) {
return value;
}
final converter = typeConverter ?? _converter;
if (value != null && converter.canConvert(value, bool)) {
final converted = converter.convertValue(value, bool);
if (converted is bool) {
return converted;
}
}
throw SpelEvaluationException(
SpelMessage.typeConversionError,
inserts: [_typeName(value), 'bool'],
);
}