creating rollback statement for changeset leads to general object value printed (using xml format)

Hello,

I just started with Liquibase (version 3.1.1) and came across following situation:

I created a rollback statement (with a delete change inside) and added it to a ChangeSet.

Then I wrote the ChangeLog via the XMLChangeLogSerializer and in the resulting XML file the rollback statement is displayed as following:

[Lliquibase.change.Change;@5c2a25

I stepped through the liquibase library and saw following:

In ChangeSet.getRollbackChanges there is an Array returned (explicitly casting the rollBackChanges list to Array). TheXMLChangeLogSerializer then on setValueOnNode checks for an instance of Collection, which excludes the rollback array. Therefore as the rollback value the array is printed with the standard toString method.

I’m still pretty new with liquibase but I’m not sure this is the wanted behaviour.

So questions:

  1. Why is the rollback changes getter returning an array? And not the (unmodifiable) list as it is the case with the changes list?

  2. Is there something I should consider when creating a rollback change? In principle I only did:

  1. DeleteDataChange deleteRollback = new DeleteDataChange();
  2. deleteRollback.setTableName(tableName);
  3. deleteRollback.setWhere(rollbackWhereStatement.toString());
  4. changeSet.addRollbackChange(deleteRollback);

Thank you…

EDIT:

Playing around with XMLChangeLogSerializer’s source code I saw this:

Changing the method setValueOnNode(Element node, String objectName, Object value, LiquibaseSerializable.SerializationType serializationType) by adding something like this if clause:

  1. if (value instanceof Object[]) {
  2. if (serializationType.equals(LiquibaseSerializable.SerializationType.NESTED_OBJECT)) {
  3. String namespace = LiquibaseSerializable.STANDARD_CHANGELOG_NAMESPACE;
  4. Element newNode = createNode(namespace, objectName, "");
  5. for (Object child : (Object[]) value) {
  6. setValueOnNode(newNode, objectName, child, serializationType);
  7. }
  8. node.appendChild(newNode);
  9. }
Then my resulting changelog XML shows the expected rollback tags.
  1. TABLE_TEXT='Text' AND TABLE_TEXT_INFO='another text' AND SOME_ID='7' AND SOME_OTHER_ID='1'