Skip to main content

Custom Conversions

goal

A Conversion function processes the input from the table column to something that can be used by a mask or randomize Rule.

To write your own Custom Conversion function, simply implement the IConversion.java interface and @Override the Object convert(String input) function.

Place your custom Java function inside your root package/conversions folder in the genereated project.

Notes

  • The column is always read as a String
  • Use a conversion to change the type or manipulate the data entry
  • The convert function always assumes a String input, and may return any other Object type
  • When used for a randomize rules, it converts the string into a type supported for the randomize rule

Conversion Interface

public interface IConversion {
Object convert(String input) throws Exception;
}

Java Examples

public class ParseDigits implements IConversion {

public static final String LABEL = "ParseDigits - simply remove all non-digits";

@Override
public Object convert(String txt) {
if(txt==null)
return "0";
char[] chars = txt.toCharArray();
StringBuilder sb = new StringBuilder();
for (char c : chars) {
if(Character.isDigit(c))
sb.append(c);
}
return sb.length()==0?"0":sb.toString();
}
}

ANO Usage Examples

  • You must explicitly import Custom Conversion functions before the Tasks and Rules Section
table Person
column text age
size 16

conversion example.anonymizer.conversions.ParseDigits

task MyTask {
update Person
mask age
format %s
column age
convert ParseDigits // Remove digits from column values
}