Convert
Goal
Use convert
to parse the values of an input source, using a java method, before it enters the anonymization logic described in the .ano
file.
The difference between a convert
and a transform
is that a convert
is done on an input source
and a transform
is done on the output of the anonymization rule
, i.e., the output of the format
string.
Use cases for convert
Use convert
when writing
randomize
rules, because the input source values are read as strings by defaultmask
rules, when you want to convert an input source before doing the anonymization operation- This may be required by your business logic
- E.g., converting a date field to an int field giving current age since date
- This may be required by your business logic
For simple conversions, use the built-in conversion functions described below. For business specific logic, you will need to write your own conversion function.
Ano Structure and Examples
- Structure
- String2Decimal Randomize Example
- Custom ParseDigits Example
update <table>
mask <column>
format %s
column <column>
convert <conversion-function>
...
randomize <colummn>
type <type>
format <format>
convert <conversion-function>
offset <offset>
flat-noise <flat-noise>
percentage-noise <percentage-noise>
...
randomize INITIALPRICE
type decimal
format %.2f
convert String2Decimal
offset 0.0
flat-noise 0.0
percentage-noise 1.0
...
// importing custom conversion function
conversion example.anonymizer.conversions.ParseDigits
task <task-name> {
update ADDRESS
mask POSTALCODE
format %s
column POSTALCODE
convert ParseDigits
}
Built-in Conversion functions
All input to the randomize function is read as a string.
Replace <conversion-function>
with the correct conversion function, defined by the input source type and desired format:
Type | Conversion Function | Return type | Expected format from conversion |
---|---|---|---|
Date | String2Date | java.time.LocalDate | yyyy-MM-dd |
DateTime | String2DateTime | java.time.LocalDateTime | yyyy-MM-dd HH:mm:ss |
Time | String2Time | java.time.Time | HH:mm:ss |
Integer | String2Integer | java.lang.Integer | Decimal integer with or without sign |
Decimal | String2Decimal | java.lang.Double | Decimal number as accepted by the valueOf method in class Double |
Custom Conversions
If you want to write your own conversions, see Custom Conversions for details.