DBZ-3966 Serializing hasDefaultValue in JsonTableChangeSerializer

This commit is contained in:
jiabao.sun 2021-11-04 14:50:55 +08:00 committed by Gunnar Morling
parent d1cae3f3b7
commit 2987e96c44
2 changed files with 13 additions and 0 deletions

View File

@ -91,6 +91,7 @@ private Document toDocument(Column column) {
document.setBoolean("autoIncremented", column.isAutoIncremented());
document.setBoolean("generated", column.isGenerated());
document.setString("comment", column.comment());
document.setBoolean("hasDefaultValue", column.hasDefaultValue());
column.defaultValueExpression().ifPresent(d -> document.setString("defaultValueExpression", d));
@ -161,10 +162,14 @@ private static Table fromDocument(TableId id, Document document) {
columnEditor.comment(columnComment);
}
Boolean hasDefaultValue = v.getBoolean("hasDefaultValue");
String defaultValueExpression = v.getString("defaultValueExpression");
if (defaultValueExpression != null) {
columnEditor.defaultValueExpression(defaultValueExpression);
}
else if (Boolean.TRUE.equals(hasDefaultValue)) {
columnEditor.defaultValueExpression(null);
}
Array enumValues = v.getArray("enumValues");
if (enumValues != null && !enumValues.isEmpty()) {

View File

@ -54,6 +54,14 @@ public void canSerializeAndDeserializeHistoryRecord() throws Exception {
.defaultValueExpression("1")
.enumValues(Collect.arrayListOf("1", "2"))
.create())
.addColumn(Column.editor()
.name("third")
.jdbcType(Types.VARCHAR)
.type("VARCHAR")
.length(22)
.optional(true)
.comment("third comment")
.create())
.setPrimaryKeyNames("first")
.setComment("table comment")
.create();