YunaiV/yudao-cloud · error · UnexpectedLiquibaseException
Cannot convert type {} to a boolean value
Error message
Cannot convert type {} to a boolean value What it means
BooleanType.objectToSqlValue only converts String, Long, Number, DatabaseFunction and Boolean instances. Any other Java type (Date, char[], custom object, null-with-unexpected-type) falls to the final else and throws, reporting the offending class name in the message.
Source
Thrown at sql/dm/flowable-patch/src/main/java/liquibase/datatype/core/BooleanType.java:108
} else {
returnValue = this.getFalseBooleanValue(database);
}
} else if (value instanceof Number) {
if (value.equals(1) || "1".equals(value.toString()) || "1.0".equals(value.toString())) {
returnValue = this.getTrueBooleanValue(database);
} else {
returnValue = this.getFalseBooleanValue(database);
}
} else if (value instanceof DatabaseFunction) {
return value.toString();
} else if (value instanceof Boolean) {
if (((Boolean) value)) {
returnValue = this.getTrueBooleanValue(database);
} else {
returnValue = this.getFalseBooleanValue(database);
}
} else {
throw new UnexpectedLiquibaseException("Cannot convert type " + value.getClass() + " to a boolean value");
}
return returnValue;
}
protected boolean isNumericBoolean(Database database) {
if (database instanceof Firebird3Database) {
return false;
}
if (database instanceof DerbyDatabase) {
return !((DerbyDatabase) database).supportsBooleanDataType();
} else if (database instanceof DB2Database) {
return !((DB2Database) database).supportsBooleanDataType();
}
return (database instanceof Db2zDatabase)
|| (database instanceof FirebirdDatabase)
|| (database instanceof MSSQLDatabase)
|| (database instanceof MySQLDatabase)View on GitHub (pinned to 477be9dd49)
Solutions
- Convert the value to String/Boolean/Number before setting it: String.valueOf(value) for '1'/'0'/'true'/'false'.
- Use Boolean.TRUE/FALSE or Integer 1/0 for numeric-boolean databases.
- Wrap computed SQL in new DatabaseFunction("...") instead of raw objects.
- Inspect the class name printed in the message to find the exact caller passing the bad type.
Example fix
// before
column.setDefaultValue(Character.valueOf('1'));
// after
column.setDefaultValue("1"); Defensive patterns
Strategy: type-guard
Validate before calling
Object v = column.getDefaultValue();
if (!(v == null || v instanceof String || v instanceof Boolean || v instanceof Number || v instanceof DatabaseFunction)) {
v = String.valueOf(v); // coerce before Liquibase sees it
column.setDefaultValue(v);
} Type guard
static boolean convertibleToLiquibaseBoolean(Object v) {
return v == null || v instanceof String || v instanceof Boolean
|| v instanceof Number || v instanceof DatabaseFunction;
} Try / catch
try { sqlValue = boolType.objectToSqlValue(v, db); }
catch (UnexpectedLiquibaseException e) {
if (e.getMessage().startsWith("Cannot convert type")) {
sqlValue = v == null ? null : String.valueOf(v); // explicit fallback
} else throw e;
} Prevention
- Map external values to String/Boolean/Number at the boundary of any Liquibase programmatic API
- Beware Character values from CSV/ORM layers — box to String explicitly
When it happens
Trigger: Programmatic API use where a Changeset/column value is set with an unsupported object, e.g. Column.setDefaultValue(Character 'Y'), a java.util.Date, or a char primitive boxed as Character. Character values are the classic case: '1' as char is not the String "1".
Common situations: Code that builds Liquibase Change objects dynamically and passes raw types from an ORM or CSV import; upgrading Liquibase versions where previously-silently-coerced types now fail; using setDefaultValue(new Character('0')).
Related errors
AI-assisted analysis of YunaiV/yudao-cloud@477be9dd49 (2026-08-14).
Data as JSON: /api/errors/25a50151f5d65d79.
Report an issue: GitHub.