# Custom Datatype for adding custom logic

**URL:** <https://forum.liquibase.org/t/custom-datatype-for-adding-custom-logic/10436>\
**Category:** General Discussion\
**Created:** [April 27, 2025, 12:50pm UTC](https://forum.liquibase.org/t/custom-datatype-for-adding-custom-logic/10436 "2025-04-27T12:50:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![misc1987](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@misc1987](https://forum.liquibase.org/u/misc1987)\
**Post date:** [April 27, 2025, 12:50pm UTC](https://forum.liquibase.org/t/custom-datatype-for-adding-custom-logic/10436/1 "2025-04-27T12:50:15Z")

</div>

my project is in Springboot 3.4.4 and liquibase version - 4.29.2, I have a requirement to change the specific employee name before inserting to tables. Project uses liquibase yaml files. Have added a custom datatype for a field. Something like this:

```auto
creat_emp_table.yaml

- column:
    name: emp_name
    type: customnvarchar(32)

```

And added a java file CustomNvarchar.java , also added a registry in META-INF\services\ liquibase.datatype.LiquibaseDataType

```auto
@DataTypeInfo(name="customnvarchar",aliases = {"java.lang.String"},
        minParameters = 0, maxParameters = 1, priority = LiquibaseDataType.PRIORITY_DEFAULT+1)
public class CustomNvarchar extends NVarcharType {

    @Override
    public String objectToSql(Object value, Database database) {
        if (value != null && !"null".equals(value.toString().toLowerCase(Locale.US)) && value.toString().contains("USERA")) {
            value = StringUtils.replace(value.toString(), "USERA", "USERB");
        }
        return super.objectToSql(value, database);
    }
}

```

```auto
load_emp.yaml

databaseChangeLog:
  - changeSet:
      id: load_emp
      author: 
      runOnChange: true
      changes:
        - loadUpdateData:
            schemaName: ${schemaName}
            tableName: emp
            primaryKey: emp_id
            file: emp/emp.csv
            relativeToChangelogFile: true

```

But liquibase performs the java logic validation for all the columns for all tables irrespective of if the column is “customnvarchar” or not. This will increase our liquibase performance run time.

Please guide me if any other config needs to be added to run the java logic only for the “customnvarchar” fields.
