class SchemaToJsonMapper {

    public static String exportTableDefinitionAsJson( @NonNull CatalogTable catalogTable, boolean exportPrimaryKey, boolean exportDefaultValues ) {
        List<JsonColumn> columns = new LinkedList<>();
        for ( CatalogColumn catalogColumn : Catalog.getInstance().getColumns( catalogTable.id ) ) {
            String defaultValue = null;
            String defaultFunctionName = null;
            if ( exportDefaultValues ) {
                if ( catalogColumn.defaultValue != null ) {
                    defaultValue = catalogColumn.defaultValue.value;
                    defaultFunctionName = catalogColumn.defaultValue.functionName;
                }
            }
            columns.add( new JsonColumn(
                    catalogColumn.name,
                    catalogColumn.type.name(),
                    catalogColumn.length,
                    catalogColumn.scale,
                    catalogColumn.nullable,
                    defaultValue,
                    defaultFunctionName ) );
        }
        List<String> primaryKeyColumnNames = null;
        if ( exportPrimaryKey ) {
            for ( CatalogKey catalogKey : Catalog.getInstance().getTableKeys( catalogTable.id ) ) {
                if ( catalogKey.id == catalogTable.primaryKey ) {
                    primaryKeyColumnNames = catalogKey.getColumnNames();
                    break;
                }
            }
        }
        JsonTable table = new JsonTable( catalogTable.name, columns, primaryKeyColumnNames );
        return gson.toJson( table );
    }

}